Adding Objects with Actionscript

 

1. If you have not already done so you should first complete the Basic Tutorial, then open the file that you created.


2. Select the 3DEnvironment on the stage and open the properties panel. Assign an instance name to the component, for the purposes of this tutorial name it world.

screen shot

 


3. De-select the component by clicking on the frame in the timeline. Press Alt+F9 to open the Actions panel.


Enter the code below:

var obj:Object = {x:0, y:0, z:0, regName:"newCircle", linkageId:"circle"};
world.addObj(obj);


This script creates a new object with the first line and adds the object to the 3DEnvironment component with the second line.


4. Immediately below the script you entered in step 3, add the following code:


var lis:Object = new Object(); lis.onWorldInit = function(){ world.motionObj("newCircle", {x:200, z:200}, 10); } world.addEventListener("onWorldInit", lis);

This script creates another object in the first line. Then it uses the component's onWorldInit function to call the component's motionObj method as soon as the 3DEnvironment is initialized. Finally it registers the lis object with the 3DEnvironment instance.


5. Press Ctrl+S (Win) or Cmnd+S (Mac) to save your file and Ctrl+Enter (Win) or Cmnd+Enter (Mac) to test your file.

 

When you test your file you'll see the new object has been added and moves to its new coordinates as soon as the component initializes.

Note: You can find more information on this script in the Actionscript Reference section of this userguide.