登录,但是,然后,错误

时间:2016-03-11 21:53:28

标签: android actionscript-3 google-play-services google-play-games

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

当我安装应用程序时,我必须登录。当我登录时,我没有遇到任何问题。如果我关闭应用程序,然后我再次打开游戏,说我没有登录。所以,我点击登录,我登录但是然后我收到了SIGN_IN_FAILS错误。在代码中,首先我检查用户是否已登录,如果未登录,则显示“登录”按钮。但是之前联系过的人会发生什么?我有一个"否则"告诉他,如果他已经登录,他可以继续'但总是说我没有登录,我必须登录!但如果我再次登录,我会收到错误!

PS。我使用的是freshplanet / laurentiu ANE / library。

**编辑**

CODE:

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;
}

知道会发生什么事吗?

1 个答案:

答案 0 :(得分:0)

可能会有所帮助的一些事情:

我认为你顶部的东西应该是一个构造函数。对于这种类型的代码,使用事件侦听器,你可能会更好地创建外部.as3文件并附加到文档类或movieClip基类,而不是将代码放在时间轴中,因为我认为你的代码可能并不总是移动时可用吗?

我注意到你这样做:

  

this.checkeStatus();

马上,这可能会这样做:

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

或者它可能会这样做:

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

但我认为这并不重要,因为在那之后,你回到 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);
    }
}

因为在所有情况下,但是第一次切换第二个与第一个相反。