mardi 28 février 2017

storing and retrieving multiple shared object

I am doing sign up and sign in using sharedobject in AS3. I am storing username and password in different shared object variables. It stores successfully. But while retrieving and checking the username and password during sign-in, i don't know about how to relate particular username with the password assigned to that username as both are stored in the different shared object variables. Here is my code.

//sign up code

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;   

}

//sign in code

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

Aucun commentaire:

Enregistrer un commentaire