登陆,然后报错

Login, but then, error

我正在使用 Flash CC 开发应用程序。我正在使用 Google Play 服务来登录应用程序中的人员,但我遇到了问题。

当我安装应用程序时,我必须登录。当我登录时,我没有遇到任何问题。如果我关闭应用程序然后再次打开游戏,会提示我未登录。因此,我单击登录,登录但随后收到 SIGN_IN_FAILS 错误。在代码中,首先我检查用户是否登录,如果没有登录,我显示登录按钮。但是以前联系过的人会怎样呢?我有一个 "else" 告诉他如果他已经登录,他可以 'Continue'。但是总是说我没有登录,我必须登录!但是,如果我再次登录,就会出现错误!

PS。我正在使用 freshplanet/laurentiu ANE/library.

** 编辑 **

代码:

import com.freshplanet.ane.AirGooglePlayGames.AirGooglePlayGames;
import com.freshplanet.ane.AirGooglePlayGames.AirGooglePlayGamesEvent;
import com.laurentiu.ane.AirGooglePlayServices.AirGooglePlayServices;

var airGooglePlayGames: AirGooglePlayGames = AirGooglePlayGames.getInstance();

airGooglePlayGames.addEventListener(AirGooglePlayGamesEvent.ON_SIGN_IN_SUCCESS, onSignInSuccess);
airGooglePlayGames.addEventListener(AirGooglePlayGamesEvent.ON_SIGN_OUT_SUCCESS, onSignOutSuccess);
airGooglePlayGames.addEventListener(AirGooglePlayGamesEvent.ON_SIGN_IN_FAIL, onSignInFail);

this.checkeStatus();
button_login.addEventListener(MouseEvent.CLICK, googleSignIn);
btn_out.addEventListener(MouseEvent.CLICK, googleSignOut);
btn_out.visible = false;
button_login.visible = false;

function googleSignIn(e: MouseEvent = null): void {
AirGooglePlayGames.getInstance().signIn();
}
function checkeStatus() {
if (!AirGooglePlayGames.getInstance().isSignedIn()) {
    // Always stay here when I reopen the app
    btn_out.visible = false;
    button_login.visible = true;
} else {
    // I never arrive here
    texto.text = "PLAYERID: " +     AirGooglePlayGames.getInstance().getActivePlayerID();
    loadingBar.gotoAndStop(2);
    button_login.visible = false;
    btn_out.visible = true;
}
}
function onSignInSuccess(e: AirGooglePlayGamesEvent): void {
// I only arrive here if is the first time I open the app and login for first time
texto.text = "PLAYERID: " +     AirGooglePlayGames.getInstance().getActivePlayerID();
loadingBar.gotoAndStop(2);
button_login.visible = false;
btn_out.visible = true;
}
function onSignOutSuccess(e: AirGooglePlayGamesEvent): void {
texto.text = "SIGN OUT OKAY!";
loadingBar.gotoAndStop(1);
button_login.visible = true;
btn_out.visible = false;
}
function onSignInFail(e: AirGooglePlayGamesEvent): void {
texto.text = "SING IN FAIL: " + e;
loadingBar.gotoAndStop(1);
button_login.visible = true;
btn_out.visible = false;
}
function googleSignOut(e: AirGooglePlayGamesEvent): void {
texto.text = "SIGN OUT PROGRESS";
airGooglePlayGames.signOut();
loadingBar.gotoAndStop(1);
button_login.visible = true;
btn_out.visible = false;
}

知道会发生什么吗?

一些可能有帮助的事情:

我认为你在顶部的东西应该在构造函数中。对于这种类型的代码,使用事件侦听器,制作外部 .as3 文件并附加到文档 class 或电影剪辑库 class 可能比将代码放在时间轴中更好,因为我认为您的代码在您移动时可能并不总是可用??

我注意到你这样做了:

this.checkeStatus();

马上,可能会这样做:

btn_out.visible = false;
button_login.visible = true;

或者它可能会这样做:

button_login.visible = false;
btn_out.visible = true;

但我认为这并不重要,因为在那之后,您 return 转到 this.checkeStatus() 下的行,然后得到:

btn_out.visible = false;
button_login.visible = false;

所以不管 this.checkeStatus() 发生了什么,你最终都会关闭两个按钮,不是吗?所以也许尝试将 this.checkeStatus(); 向下移动到构造函数的底部,这样它就可以放在最后。

将所有这些重复的 visible = false / true 行分解成它们自己的函数可能更紧凑,更容易混淆,例如:

private function setStatusButtonsVisible(status:Boolean){
    button_login.visible = status;
    btn_out.visible = !status;
    if (status){
        loadingBar.gotoAndStop(2);
    }else{
        loadingBar.gotoAndStop(1);
    }
}

因为在所有情况下,除了第一个,您要将第二个切换为与第一个相反。