ActionScript 3 XML MP3 Player
February 21, 2008 by jared
Click here for the version 1.1 update.
Alternatively click here for the Pro version of this player. Only $5.00!
Creating Custom Methods in ActionScript 3
February 9, 2008 by jared
Click here to download the sample files.
Methods are simply functions inside a class. Think of a class as an object, lets say a car engine.

So here’s the basic setup for a Car engine class object in ActionScript 3. (CarEngine.as)
Open up CarEngine.as. Here we have a class named CarEngine.
Inside the class we have declared a boolean (boolean returns either a true or false value) variable called _engineStatus to check the status of the car engine.
public class CarEngine extends MovieClip {
private var _engineStatus:Boolean;
public function CarEngine() {
Inside the constructor (code inside the constructor is executed immediately when the class is initialized) we find the following
_engineStatus = false;trace("Car's engine is currently " + this._engineStatus);
What these two lines do is first declare the _engineStatus (that we declared earlier as a boolean variable) as false, and send a trace statement to return the current value of the car engine.
The next two functions enables the CarEngine class to “get” and “set” the current status of the engine.
public function get engineStatus() {
return _engineStatus;
}
public function set engineStatus(value) {
_engineStatus = value;
}
Now all that’s left is to call this class from an external source. Open up Car.fla, click on the first frame and press F9 on your keyboard. It should open up the actions panel and you should see some code in there.
The first line initializes an instance of the Car Engine class.
var _carEngine:CarEngine = new CarEngine();
As mentioned above, code inside the constructor is executed immediately when the CarEngine class is initialized. Therefore it should return us a trace statement in the output window, telling us that the engine is currently false.
Now lets modify the engine status and change it to true.
_carEngine.engineStatus = true;
And finally lets check if the engine is now true
trace("Car's engine is changed to " + _carEngine.engineStatus);
And it is!
Click here to download the sample files.
Calling an External Class in AS 3
February 4, 2008 by jared
This is how you call an external .as file (which is essentially a class).
1.) Download the sample files.
2.) Brief
You should see 3 files
- CallingExtClass.fla
- MainClass.as
- AnotherClass.as
Open CallingExtClass.fla, and compile it to swf by pressing CTRL + Enter.
You should see this in the Output window
“this is main doc Class” is being executed from MainClass.as
and “this is from the AnotherClass.as file” is from, well, AnotherClass.as.
3.) How does it work?
MainClass.as is the document class for CallingExtClass.fla
Open MainClass.as, and observe that the following piece of code in the constructor creates a new instance of AnotherClass.as
var _anotherClass:AnotherClass = new AnotherClass();
This simply means an object called _anotherClass has been created (loaded into the memory) but not yet placed on the stage. To do that we need the following line of code.
addChild(_anotherClass)
Think of the stage as a Parent object. Anything that is added to the stage will naturally be known as a Child object, hence, addChild(name_of_the object).
That’s how you reference / call an external class and load it onto the stage.
ActionScript 3 Dynamic XML Slideshow
February 2, 2008 by jared
Update (18 May 08)


