PDA

Click to See Complete Forum and Search --> : shared object?



gamist
09-29-2002, 09:48 AM
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);
}
}

psychlonex
09-29-2002, 10:59 AM
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:



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:


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:



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

gamist
09-29-2002, 11:04 AM
That worked! Now I understand the concept. Thanks so much.

gamist