dcsimg
A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Shared Object problem.

  1. #1
    Senior Member
    Join Date
    Nov 2004
    Location
    I'm a brumie, currently in London working for the man
    Posts
    147

    Shared Object problem.

    Hi i've building this game in as3 for a while now, and well i'm trying to save some form data so when a player returns he / she has the form auto filled in.

    Only problem is while I can get it to save the details once a player has submited.. I can't get it to work for a fresh load.

    I'm getting some lovely.. errors, refering to the fact that the object is null or false or otherwise empty.

    this is stoping my movie from progressing.. anyone else know how i can over ride this and stop it causing my movie to halt.
    Code:
    //ref the object at start of movie
    var so = SharedObject.getLocal("UserDetailsNew");
    
    //load the data in, problem ocures when these fields are blank, but how      //else am i to do it?
    
    	formFill.email.inputTXT.text =  so.data.email;
    	formFill.fname.inputTXT.text =  so.data.fname;
    	formFill.lname.inputTXT.text =  so.data.lname;
    	formFill.phone.inputTXT.text =  so.data.phone;
    	formFill.dob.inputTXT.text =    so.data.dob;
    	formFill.town.inputTXT.text =   so.data.town;
    	formFill.opt1.selected = so.data.opt1;
    	formFill.opt2.selected = so.data.opt2;
    	formFill.tc.selected = so.data.tc;
    
    
    //Data filled added to SO
    
    //Save Data To Cookie (Shared Object);
    	so = SharedObject.getLocal("UserDetailsNew")
    	so.data.email = txtInput[0].inputTXT.text ;
    	so.data.fname = txtInput[1].inputTXT.text ;
    	so.data.lname = txtInput[2].inputTXT.text ;
    	//Phone
    	so.data.phone = path.phone.inputTXT.text ;
    	//trace("variableB.phone = " + variablesB.phone);
    	//dob
    	so.data.dob  =  txtInput[3].inputTXT.text;
    	//
    	so.data.town =  txtInput[4].inputTXT.text;
    	//
    	so.data.gender = gender;
    	so.data.opt1 = opt1;
    	so.data.opt2 = opt2;
    	so.data.tc = tc;
    	so.flush();
    
    //
    So there it is.. how can i fill make sure it doesn't halt my movie, but yet fill in the user details from the shared object if their is one

    Andy

  2. #2
    Senior Member Computer Dork's Avatar
    Join Date
    Mar 2001
    Location
    St. Louis
    Posts
    1,026
    If you run this code, it makes one, or overwrites what currently exists.

    I guess I don't really understand what the problem is. Is flash crashing? are you unable to retrieve it later?

  3. #3
    Senior Member
    Join Date
    Nov 2004
    Location
    I'm a brumie, currently in London working for the man
    Posts
    147
    The fill in data where it trys to set the form text cashes the script to break, as it it won't progress any futher here's more of the script.

    Basically when the user first comes into the game, no values are in the shared object, therefore it can't load them and I get this error.

    It's fine once a shared object has been created, but for a fresh user, it just stops working ie calling the form.

    Code:
    //PULL DATA BACK IN
    	so = SharedObject.getLocal("UserDetailsNew");
    	//
    	formFill.email.inputTXT.text =  so.data.email;
    	formFill.fname.inputTXT.text =  so.data.fname;
    	formFill.lname.inputTXT.text =  so.data.lname;
    	formFill.phone.inputTXT.text =  so.data.phone;
    	formFill.dob.inputTXT.text =    so.data.dob;
    	formFill.town.inputTXT.text =   so.data.town;
    	formFill.opt1.selected = so.data.opt1;
    	formFill.opt2.selected = so.data.opt2;
    	formFill.tc.selected = so.data.tc;
    
    
    //Save Data To Cookie (Shared Object);
    	so = SharedObject.getLocal("UserDetailsNew")
    	so.data.email = txtInput[0].inputTXT.text ;
    	so.data.fname = txtInput[1].inputTXT.text ;
    	so.data.lname = txtInput[2].inputTXT.text ;
    	//Phone
    	so.data.phone = path.phone.inputTXT.text ;
    	//trace("variableB.phone = " + variablesB.phone);
    	//dob
    	so.data.dob  =  txtInput[3].inputTXT.text;
    	//
    	so.data.town =  txtInput[4].inputTXT.text;
    	//
    	so.data.gender = gender;
    	so.data.opt1 = opt1;
    	so.data.opt2 = opt2;
    	so.data.tc = tc;
    	so.flush();
    	//
    	trace("this is the saved object = " + so.data)
    	//
    	//Last Switch before send
    	firstData = false;
            form.x = 435/2;
    	form.y = 435/2;
    	TweenLite.from(form,1,{alpha:0, delay:0});
    Last edited by ukspudnie; 02-29-2008 at 02:05 PM.

  4. #4
    Senior Member Computer Dork's Avatar
    Join Date
    Mar 2001
    Location
    St. Louis
    Posts
    1,026
    ok... when you say 'causes the script to break' - what kind of errors do you get? Does it crash flash? What happens?

  5. #5
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Quote Originally Posted by ukspudnie
    I'm getting some lovely.. errors, refering to the fact that the object is null or false or otherwise empty.
    I am not sure which was the right version, since I don't have Flash here, either
    var so = SharedObject.getLocal("UserDetailsNew");
    if(so.data!=null)
    {
    ......
    }

    or

    if(so!=null)
    {
    ......
    }
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  6. #6
    Senior Member
    Join Date
    Nov 2004
    Location
    I'm a brumie, currently in London working for the man
    Posts
    147

    Unhappy here's what i've got

    I've tried both thoose methods without luck.. I know the theory behind it, but for some reason I can seem to get it to work..

    any ideas? just getting this error

    Code:
    TypeError: Error #2007: Parameter text must be non-null.
    at flash.text::TextField/set text()
    at MethodInfo-338()
    Thats because it can't find the cookie.. as it's not been set yet.. etc etc, i need the first setting to make sure that next time the game loads in remembers who you are etc etc.

    /// Code Used

    Code:
            so = SharedObject.getLocal("UserDetails2")
    	//
    	if(!so == null){
    		trace("setting cookie");
    	//
    	so.data.email = "" ;
    	so.data.fname = "" ;
    	so.data.lname = "" ;
    	//Phone
    	so.data.phone = "" ;
    	//dob
    	so.data.dob  =  "";
    	//
    	so.data.town =  "";
    	//
    	so.data.gender = "";
    	so.data.opt1 = true;
    	so.data.opt2 = "";
    	so.data.tc = "";
    	so.data.dataSave = false;
    	so.data.emailsend == false;
    	}else{
    		trace("cookie found")
    	}

  7. #7
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    if(!so == null){

    !so: what does this mean?
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  8. #8
    Senior Member
    Join Date
    Nov 2004
    Location
    I'm a brumie, currently in London working for the man
    Posts
    147
    i'm not sure I tried your methods.. but they didn't work either.. so i was just playing with the var to see what would work.. ov nothing did.

    i've tried

    Code:
    !so.data == null
    so!.data = null
    so.data == Null
    so.data = Null
    so.data == false
    !so == Null
    
    so == "undefined"
    i'm at my wits end onto y i can't get it to work.

    Andy.

  9. #9
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    When you declare the shared object to have it available from different sites you need to place it on root:
    so = SharedObject.getLocal("UserDetails2","/");

    Ok,

    I checked my own files. You need to ask specifically, for example:

    if(so.data.email!=undefined)
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  10. #10
    Senior Member
    Join Date
    Nov 2004
    Location
    I'm a brumie, currently in London working for the man
    Posts
    147
    sorry that didn't seem to work grrr.

    lol

    it just crashed my flash instead.

  11. #11
    Senior Member Computer Dork's Avatar
    Join Date
    Mar 2001
    Location
    St. Louis
    Posts
    1,026
    Don't check to see if so is null.

    if (so.size == 0) is basically 'null'. It will always be definied - because you are defining it when you make the getLocal call. if it's size is 0, there's nothing in it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center