An example of a file using this code can be downloaded here and see its usage on Whirled here. The official Whirled tutorial for persistent memory can be found here.
In order to use Whirled functionality, the Whirled SDK needs to be set up. Follow the basic avatar tutorial on the wiki if not already set up.
Create your toy in Flash using online tutorials relating to Flash and AS3. Write code in your file by creating a new layer and while on the first frame press F9. ActionScript is written similarly to JavaScript with some differences. As an example, create a string variable and print it to the console (press F2 to open the output console):
var word:String = "test"; trace(word);Common functions used in AS3 include stop(), start(), play(), and gotoAndPlay(1, "scene"). You can look up specific examples to suit your project. If you get an error, it will appear in the output window, where you can double click on the error to show where it's coming from.
Note that your file can be uploaded as a furniture or as a toy, but it is standard to upload interactive items as toys (and will be more highly valued as a toy).
First import libraries from the Whirled SDK:
import com.whirled.ToyControl; import com.whirled.ControlEvent;
Then create a new toy control:
var _ctrl :ToyControl = new ToyControl(this);
Use _ctrl.setMemory when you want to propogate a value to everyone, so that the toy can use this value to update its appearance or functionality. Replace exampleVariable with the name of the variable you want saved on Whirled, and newValue with the value of the variable. Ex. _ctrl.setMemory("customText", "Hello Whirled");
_ctrl.setMemory("exampleVariable", newValue);
Then use the following line to listen for the memory change event. Replace updateToy with the name of the function you will create that applies updates to the toy.
_ctrl.addEventListener(ControlEvent.MEMORY_CHANGED, updateToy);
Replace updateToy with the function from the previous step.
function updateToy (o :Object = null) :void { var memoryValue:Object = _ctrl.getMemory("exampleVariable", 0xffbdce); // code to update the toy's appearance or behavior }