A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: shared object?

  1. #1
    Senior Member
    Join Date
    Jun 2001
    Posts
    343
    I am still a little confused on how to make something in my movie into a shared object. I have a button; when pressed changes the frame of a mc. The first frame contains a box that is one color and the second frame it is another color. How do I make it so all the users will see the the box in the mc change colors no matter who clicks the button? See below:

    nc = new netConnection();
    nc.connect("rtmp://flashcom.mywebsite.com/examples");
    so = SharedObject.getRemote("box",nc.uri,false);
    so.connect(nc);

    function doChangeColor() {
    if (ChangeColor_btn.getLabel() == "Blue") {
    ChangeColor_btn.setLabel("Red");
    _root.box.gotoAndStop(2);
    } else if (ChangeColor_btn.getLabel() == "Red") {
    ChangeColor_btn.setLabel("Blue");
    _root.box.gotoAndStop(1);
    }
    }

  2. #2
    psx = new Moderator();
    Join Date
    Jan 2001
    Posts
    923
    You can use the so almost like any other object in actionscript. So to add the box frame to it, you'd do something like:

    Code:
    function doChangeColor() { 
    if (ChangeColor_btn.getLabel() == "Blue") { 
    ChangeColor_btn.setLabel("Red"); 
    _root.box.gotoAndStop(2); 
    
    so.data.boxFrame = 2;
    
    } else if (ChangeColor_btn.getLabel() == "Red") { 
    ChangeColor_btn.setLabel("Blue"); 
    _root.box.gotoAndStop(1); 
    
    so.data.boxFrame = 1;
    } 
    }
    So you stick values into the so's data object. To get them out you can either grab them whenever you want, or you can use the so's onSync method:
    Code:
    so.onSync = function(list) {
    _root.box.gotoAndStop(so.data.boxFrame);
    }
    That should do it. Or you could use so.send which would work like so:

    Code:
    so.send("doColorChange",1);

    The so.send will send the "1" and "doColorChange" to all the clients connected to the so. When they receive it they'll all call their own doColorChange function.


    psx

  3. #3
    Senior Member
    Join Date
    Jun 2001
    Posts
    343

    That worked!

    That worked! Now I understand the concept. Thanks so much.

    gamist

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