存储和检索多个共享对象

时间:2017-02-28 12:32:20

标签: actionscript-3 flash shared-objects

我正在注册并使用AS3中的sharedobject登录。我将用户名和密码存储在不同的共享对象变量中。它成功存储。但是在登录期间检索和检查用户名和密码时,我不知道如何将特定用户名与分配给该用户名的密码相关联,因为两者都存储在不同的共享对象变量中。这是我的代码。

//注册代码

var signup:SharedObject = SharedObject.getLocal("newSignUp");
var signupPassword:SharedObject = SharedObject.getLocal("newSignUpPassword");
var kvalue:SharedObject = SharedObject.getLocal("kvalue1");
var k:Number;

signup_mc.signup_btn.addEventListener(MouseEvent.CLICK, signupcheck);

function signupcheck(event:MouseEvent):void {
    if(kvalue.data.updatedValue!=undefined) {
        k = kvalue.data.updatedValue;
        k_txt.text = k_txt.text + k + "\n";
        }
        else {
            k=1;
        }   
    newusername = signup_mc.username_txt.text;
    newpassword = signup_mc.password_txt.text;
    signup.data["nwusername" + k] = newusername;
    signupPassword.data["nwpassword" + k] = newpassword;      
    signup.flush();
    signupPassword.flush();
    k++;
    kvalue.data.updatedValue = k;   

}

//登录代码

login_mc.signin_btn.addEventListener(MouseEvent.CLICK, signin1);

function signin1(event:MouseEvent):void {
    for(var l:String in signup.data) {
    usersnameArr.push(signup.data[l]);      
    }
    for(var r:String in signupPassword.data) {
    passArr.push(signupPassword.data[r]);
    }

    for(var t:Number=0; t<usersnameArr.length; t++) {
        users_txt.text = users_txt.text+usersnameArr[t]+"\n";
        pass_txt.text = pass_txt.text+passArr[t]+"\n";
    }   
    getusername = login_mc.username1_txt.text;
    getpassword = login_mc.password1_txt.text;  

    for(var u:Number=0; u<usersnameArr.length; u++) {
    if(getusername==usersnameArr[u] && getpassword==passArr[u]) {           
     logged_txt.text = "signed in as "+getusername;
     myMC8= new MCVisibilityOff(login_mc);  
     break;
    }
    else {      
        logged_txt.text = "Username doesn't exist";
    }
    }
}

0 个答案:

没有答案