Yudhis
Yudhis

Reputation: 53

save and load using sharedObject in AS3

i am currently doing an experiment to save each name of the user(not replacing it every time we save the new one).

my problem is the getLocal() function.I defined a variable with the type of string to make the SharedObject store the data to local storage with the name of the variable i defined which it is the name of the each user. but i get this error:

Error #2134: Cannot create SharedObject. at flash.net::SharedObject$/getLocal() at classes::Main/saveNewUser() at classes::Main/promtSave()

here is my code

 package classes {

import flash.display.MovieClip;
import flash.net.SharedObject;
import flash.text.TextField;
import classes.user.User;


public class Main extends MovieClip {
        private var _user:User;
        private var _properties:Object;
        private var validOrNot_txt:TextField;
        private var _name_input_txt:TextField;

        //define a shared object to store our user data
        private var database:SharedObject;
        //define an array that will hold all users
        private var userList:Array;
        private var nameEntered:String;

        public function Main() {
            userList = [];

            _name_input_txt = Name_input;

            validOrNot_txt = valid_or_not_TXT;
            validOrNot_txt.autoSize = 'center';
            //_properties={Name:String,age:int,gender:String};
            // constructor code

        }
        public function get user():User{
            return _user;
        }
        private function saveNewUser():void{
            nameEntered=_name_input_txt.text;
            _user = new User();
            _user._Name = _name_input_txt.text;
            database = SharedObject.getLocal(nameEntered);
            userList.push(_user);
            database.data.Name = _user._Name;

        }

    }

}

here's the code in the timeline

import flash.events.MouseEvent;

login_btn.addEventListener(MouseEvent.CLICK, promtSave);

login_btn.buttonMode=true;

trace(Name_input.length);

function promtSave(e:MouseEvent):void{
    if(Name_input.length>1){
        saveNewUser();
    }else{
        throw(new Error('you did not enter anything'));
    }
}

anybody, please help me with this :'(

Upvotes: 0

Views: 503

Answers (0)

Related Questions