They have managed to make this process much easier than in Actionscript 2.
Start by creating a MovieClip you want to place on the stage.
Right-Click (ctrl+click MAC) on the MovieClip in the Library and either go to Properties... or Linkage...
Check the Export For Actionscript box. Notice the two text fields above this checkbox.
Base Class: is the AS3 class or object type. If you are completely new to programming, you can think of classes as blueprints for objects in flash. So, by default, if you make a MovieClip in Flash; it is based on the MovieClip class or blueprint. In later examples I'll be making classes of my own to use here instead of MovieClip. By keeping the Base class: flash.display.MovieClip, you are telling Flash that your new object is based on MovieClip (and will therefore have all the features of the MovieClip)
For this example I have given my symbol the name "Thing". I capitalized it because it is a new class even if I do not choose to further define it. Onward to adding this "Thing" to the stage.
Name an empty Layer "Actions" or something like that. Remove the Thing from the stage and go to the first frame of your Actions layer. Open the Actions panel (F9 or option+F9)
The code is the easiest part...
var theThing:Thing = new Thing();
addChild(theThing);
The variable name is also used as the reference for the object. (at least until you have more than one of them) So, if you need to change the object's properties you now...
theThing.x = 50;
theThing.y = 100;
theThing.alpha = .5;
...and so on.
If you have a child object inside your "Thing" object, you just use dot notation to get to it. For example I have a dynamic text field called text_txt inside the "Thing" symbol . Here's how I can change what it says...
theThing.text_txt.text = "Go Pods!";
One more thing. If you are not planning on using the timeline in your Thing object, change the base class to flash.display.Sprite. While one Sprite vs MovieClip will not add up to much, when you get a couple hundred of these floating around, Sprite will add up to needing fewer system resources, which of course means faster smoother files.
--Rich
Coming up next... using the Loader Class to load images and SWFs.
Current Reading... "The Tommyknockers" by Stephen King and
"Actionscript 3.0 Bible" Roger Braunstein, Mims H. Wright and Joshua J. Noble
No comments:
Post a Comment