dcsimg
A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: Saving

  1. #1
    Member
    Join Date
    Sep 2003
    Posts
    60

    Saving

    im trying to create a interactive manual for a uni asignment,

    i have created most of the program but i want to be able to save it and then load it again at a later date.

    i have read a few posts down about using flash studio pro to do it with but dont understand how it can help? as i though that fsp was only for re-outputting swf files? Obviously im wrong.

    the main problem is that i have the flash program,
    and for example i have in the program

    3 questions on frame 1 where the user fills these in and then proceeds to the next frame

    on frame 2 there will be another two or three questions which again must be filled in.

    i want to be able to save all these answers (from every frame) and then recall them at a later date. - i was looking at using a local shared object but couldnt work it out.

    the program will be running as an executable from a cd in the users machine.


    can somebody please help me? im only just getting started with avtionscrip so please be gentle!!!

  2. #2
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    This is the basic code you need to store data and retrieve it from a local shared object. You can duplicate the bolded lines as many times as you need, with as many variables as you want to store and read back.

    Code:
    	// create the local shared object
    	var so = sharedobject.getLocal("mydata"); 
    	
    	// save the data value
    	so.data.name1 = "bob the duck";
    	
    	// commit the change to disk 
    	so.flush();
    
    // then later, or maybe the next time the program runs...
    
    	// open the local shared object
    	var so = sharedobject.getLocal("mydata"); 
    	
    	// read the data we saved previously
    	value = so.data.name1;
    	
    	// spit it out so we can see it
    	trace(value);
    Last edited by Northcode; 12-24-2003 at 03:37 AM.

  3. #3
    Member
    Join Date
    Sep 2003
    Posts
    60
    hi,

    i have tried the code you supplied me but it doesnt seem to be working, the problem is probably the way that i have got my file set up or something that i havent done!!!

    would you be able to take a look at the file and advise me where i am going wrong? its driving me crazy!!! i have also downloaded several tutorials on local shared objects and tried to apply the code to mine but no success!!

    thanks for your time

    John

  4. #4
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    You should just be able to drop that code into frame 1 of a new FLA and run it to see "bob the duck" show up in the trace window (it doesn't do anything you can see in a projector). You'll have to be using Flash MX or MX 2004 (local objects didn't exist until Flash MX). Let's try and get the simple example working before we dig into your FLA

  5. #5
    Member
    Join Date
    Sep 2003
    Posts
    60
    right,

    i have done as you said and created a new flash doccument (back using mx rather than mx 2004 now tho as mx2004 kept saying undefined)

    i used a completely blank doccument and inputted the code that you gave me on frame 1...

    when i ran the program the output window appeared saying bob the duck! (presume that this is right?)

    Now...
    i have tried creating two buttons (save and load) so that i can save the work at any time...

    as it is at the moment i have three input boxes with the variables:
    pg1q1, pg1q2, pg1q3

    i tried to put the save code on the save button as follows:

    on (release){
    so=sharedobject.getlocal("mydata");
    so.data.pg1q1=q1; //i also tried replacing data with text
    so.flush();
    }

    and then on the load button:

    on (release){
    so=sharedobject.getlocal("mydata");
    q1=so.data.pg1q1;
    value=so.data.pg1q1;
    trace(value);
    }

    when i run this and input my answer into input box 1 (pg1q1) and hit save and the reload the movie and press load the output windows tells me undefined!

    im lost! i know its probably easy but its just confusing me!!!!

  6. #6
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    I dropped a couple of buttons on the stage and hooked them up to this code and it's still working. I've attached the FLA (zipped) so you can try it.

    Code:
    function OnSaveButton()
    {
    	var so = sharedobject.getLocal("getsmart"); 
    	
    	so.data.name1 = "agent 86";
    	so.data.name2 = "agent 99";
    	
    	so.flush();
    }
    
    function OnLoadButton()
    {
    	
    	var so = sharedobject.getLocal("getsmart"); 
    	
    	trace(so.data.name1);
    	trace(so.data.name2);
    	
    }
    Attached Files Attached Files

  7. #7
    Member
    Join Date
    Sep 2003
    Posts
    60
    sorry, i think we have got our wires crossed (me not explaining it!!)

    what i want it to do is that the user, will input some data into an input text box and then when a save button is pressed i want flash to save the data that they have inputed. then when the program is re-loaded / a load button pressed, for the data to be recalled and displyed in the same text boxes...

    can i not do that?

    i also need to be able to clear the data saved - if another user wants a go... if you know what i mean???

    sorry...

  8. #8
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    No, we're clear, that's what these little test functions do, but with a limited set of data items (two in this case).

    It doesn't matter if I set the data items from a string literal so.data.p1q1 = "bob" or so.data.p1q1 = _root.field_text;;

    If you use the users name as the shared object then you don't have to clear it for each user. You can clear the data items just by saving an empty string in the item like so.data.p1q1 = "".

    I've attached a new example that's closer to what you're trying to do. It allows you to play with a couple of text values, save them, restore them and nuke them from the shared object.
    Attached Files Attached Files

  9. #9
    Member
    Join Date
    Sep 2003
    Posts
    60
    thanks very much, i get it now!!!! (at long last!!)

    i have been trying to understand that for ages but i think i get it now!!!!

    thanks for all your help and patience!

    John

  10. #10
    Member
    Join Date
    Sep 2003
    Posts
    60
    one more question...


    i am faced with a new problem:

    i am wanting to be able to save the data on every page of the manual from one button, (i dont want to have to keep on clicking load on every page to load in the data.)

    so in other words i want the shared object to save data from different frames... is this possible?

    cheers
    John

  11. #11
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    If you load the data into (global) variables instead of directly into text fields then you can do it. You load the data once when the application starts and then in an enter frame event you can copy the values from the global variables into the text fields.

  12. #12
    Member
    Join Date
    Sep 2003
    Posts
    60
    forgive my ignorance but how can i do that?

    i have never used global variables before.

    i have tried using a different button on each different frame and assigning a new file name for the shared object and then loading in each different file on the appropriate frame.. e.g

    frame one says
    PHP Code:
    // loading pg1 data
    var so sharedobject.getlocal("page1");
    _root.question1.text so.data.q1;
    _root.question2.text so.data.q2;
    _root.question3.text so.data.q3;
            
    //Saving pg1 data
    function pg1save () 
    {
    var 
    so sharedobject.getlocal("page1");
    so.data.q1 _root.question1.text;
    so.data.q2 _root.question2.text;
    so.data.q3 _root.question3.text;
    so.flush();

    and then frame 2 reads
    PHP Code:
    // loading pg 2 data
    var so sharedobject.getlocal("page2");
    _root.question4.text so.data.q4;
    _root.question5.text so.data.q5;
    _root.question6.text so.data.q6;
    _root.question7.text so.data.q7;

    // saving pg2 data
    function pg2save () 
    {
    var 
    so sharedobject.getlocal("page2");
    so.data.q4 _root.question4.text;
    so.data.q5 _root.question5.text;
    so.data.q6 _root.question6.text;
    so.data.q7 _root.question7.text;
    so.flush();

    but the problem here appart from having loads of different saved files is that you need to click on the save button each page.

    i would rather either be able to click on the save button and it saves each pages data or just have it so that when you leave that frame it saves the data automatically and when you enter the frame it loads the data.

    i have got it so that when it enters a frame - if there is data storeed it loads it but if i use the same method for the save part (as shown in the load part above) it doesnt work,

    i presume that this is because the code runs on entering the frame rather than leaving the frame? is that correct?

    so i need to use either global variables or to make it save on exiting the frame and cope with loads of files?!?!?

    thanks
    John

  13. #13
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    Check out the attached FLA, it shows how to automatically call a function when you enter a new frame (and leave the old one). So you can put all you save/load code in one place and just use if statements to figure out what data to save or load based on the frame number. You can store all the data in the same shared object, you don't need to use a different one for each frame.
    Attached Files Attached Files

  14. #14
    Member
    Join Date
    Sep 2003
    Posts
    60
    thanks for all your help... sorted now... i hope!

    john

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