A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Shared Object HELP!

  1. #1

    Shared Object HELP!

    Hi there, I can't seem to retreive the variable that stored in the data from another SWF by using SharedObject. Below is what I've been trying to do.

    I got an A.swf and B.swf and each of them has 3 navigation buttons (button A, B and C). when I click on let say A button in A.swf, it will store the A button's variable to "buttonStatus" by using SharedObject so that this button will be hilighted as visited link.

    When I close the A.swf and relaunch it again, I can see the A button is highlited (visited) but when i open B.swf, the A button is not hilighted there. I'm wondering whether it is possible to retrieve the variable that stored in "buttonStatus" from A.swf so that whatever that is highligted in A.swf will be highlited in B.swf as well.

    Below is part of the script that I placed in the first frame of A.swf and B.swf
    ---------------------------------------------------------------------

    buttonStatus_so = SharedObject.getLocal("buttonStatus");
    button1_txt = buttonStatus_so.data.buttonNumber1;

    //tell the buttons to go to the particular frame based on the retrieved data.
    if (button1_txt==1){
    hilite1_mc.gotoAndStop(2);
    }else{
    hilite1_mc.gotoAndStop(1);
    }

    ---------------------------------------------------------------------anyone can help will be very much appreciated.
    thanks!
    to me, design is a way of infusing life...

  2. #2
    Flash Product Manager
    Join Date
    Mar 2002
    Posts
    140
    Where/how are you assigning a value to the buttonNumber1 variable in the data object of your sharedObject?

    Also, generally, the use of suffixes in variable names denotes the object type and triggers the code hinting. If you suffix a variable name with "_txt" the code editor will think you are referring to a TextField object. In your code you are assigning the value of "buttonStatus_so.data.buttonNumber1" - which I assume is a Numeric value - to a variable called "button1_txt". Is "button1_txt" just a container or is it the instance name of a textfield that you have on your stage?

    Thanks,
    MD

  3. #3
    Thanks for your prompt reply.

    well, I'm using flash MX , action script 1.0 so I think strict data typing shouldn't be required right?

    the button1_txt is a text field on the stage and it's the variable from data.

    thanks
    to me, design is a way of infusing life...

  4. #4
    Flash Product Manager
    Join Date
    Mar 2002
    Posts
    140
    OK, so I think your problem lies in the use of button1_txt. You're using it in a conditional that judges whether the value of button1_txt is equal to 1. If "button1_txt" is the instance name of a textfield on your stage, then its value will resolve as an object instance, not a numeric value. If you would like to compare the value of the text in the textfield, you'll want to refer to its ".text" property. Also, remember that the ".text" property of the TextField object will be a string.
    Code:
    if(button1_txt.text == "1"){
         // code here
    }

  5. #5
    ok, it works fine with that.
    when i click button1 in A.swf, the button1 will be hilighted and when I relaunch the A.swf, the button1 is still hilighted, so now I managed to store "1" to "buttonStatus_so.data.buttonNumber1"

    Now when I launch B.swf, the button1_txt should equal to "1" so that the button1 will be hilighted, but in this movie the button1_txt = 0 not 1. which means the variable that I stored in ""buttonStatus_so.data.buttonNumber1" is no longer retrievable.

    any way to fix it?

    thanks
    ks
    to me, design is a way of infusing life...

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