0

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 :'(

Gama11
  • 31,714
  • 9
  • 78
  • 100
Yudhis
  • 53
  • 7
  • So, what's the value of the **nameEntered** variable at the moment you call **SharedObject.getLocal(nameEntered);** ? – Organis Aug 13 '18 at 14:07
  • It is the text of an input textfield. I have type in something to the _name_input_text too. So why it does not working – Yudhis Aug 14 '18 at 11:33
  • The datatype is String and the value is the text of a ln input textfield and the length is above 0 – Yudhis Aug 14 '18 at 11:44
  • That what you said I guessed from code. Still, if I were facing such a problem, I'd a)tried to instantiate the **SharedObject** with a fixed name to see if it works at all, then b) traced the actual value, maybe even split it into **Array** to look for whitespaces and special characters. – Organis Aug 14 '18 at 12:33
  • Looks like i have a lot of thing to learn...i'm enjoying this. Thank you – Yudhis Aug 14 '18 at 13:36
  • Btw, are organis like yourself is a member with organis name or an administrator of this stack overflow – Yudhis Aug 14 '18 at 13:37
  • **Organis** is just an alias I assumed on a whim (or on purpose, you never know). I am **NOT** an official representative of StackOverflow or any related resource. – Organis Aug 14 '18 at 19:25

0 Answers0