Thoughts and Discoveries in AS2
For the past week i’ve been eating, drinking and breathing actionscript. Our midpoint will be on the 24th and I rebuilt the entire presentation from scratch (which might not have been appropriate given the time constraints). Nevertheless it was a great learning experience. The following is an outline/list of things I discovered about AS2:
- On Duplicating Movieclips Created With createEmptyMovieClip()
- On Using Dynamic Masks With Filter Effects
- On Some of the Differences Between Inheritance and Composition
- On Creating Instances of Class A Inside a Method of Class B and the Ensuing Scope Problems
Warning: The following appears to be gibberish to most people, my apologies. Some of these statements might be totally wrong, if you think so, please let me know so I don’t wallow in my ignorance.
On Duplicating Movieclips Created With createEmptyMovieClip
Apparently, it is impossible to duplicate a movieClip that is created with createEmptyMovieClip. It duplicates the target but not its children. For example, at runtime, if I create a movieClip called a_mc and inside it create a textField, then use duplicateMovieClip() on a_mc to create b_mc, the new clip is created, but the textField is missing. This one was a hard nut to crack, and I’m still not sure why it does this.
On Using Dynamic Masks With Filter Effects
Moving on in my journey in breaking Flash, it is impossible yet again to apply a mask to a movieClip that has a filter effect applied to it during runtime. Curiously, this works when you manually apply it during authortime. This would have made really good effects me thinks.
On Some of the Differences Between Inheritance and Composition
“When to use inheritance and when to use composition?” This one has always confused me. Apparently, one should use composition when the instance we’re creating will have properties of a movieClip in it (i.e. _x, _y, _height, _width). When an instance is NOT A movieclip, use inheritance. This means that when we want a VISUAL REPRESENTATION of a class onstage, we SHOULD use composition (i.e. a library symbol that has an ActionSript class assigned to it). I’m not really sure if you can use composition on anything other than a movieClip, and if there are times you use inheritance to extend a movieClip. Can anyone clear me up on this?
On Creating Instances of Class B Inside a Method of Class A and the Ensuing Scope Problems
When creating an instance of Class B inside Class A, you lose the reference to Class A (the this keyword) when you create an event handler for class B. The solution is to pass a reference of the parent class (this) to the new instance (if the class is a built in class, subclassing it with an additional parameter like reference is a feasible solution).
example: creating an instance of ControlledTween Class (this is class A) inside SomeClass (this is Class B):
moveAnimation = new ControlledTween(this, "_y" , Strong.easeInOut, this._y, amount, contentScrollSpeed, true, this);
subclassing a class (in this example the Tween class):
import mx.transitions.Tween;
class ControlledTween extends Tween {
private var reference:Object;
public function ControlledTween(obj:Object, prop:String, func:Function, begin:Number, finish:Number, duration:Number, useSeconds:Boolean, reference:Object) {
super(obj, prop, func, begin, finish, duration, useSeconds);
this.reference = reference;
}
}
You’re currently reading “Thoughts and Discoveries in AS2”, an entry on Visual Gratis
- Published:
- 10.10.06 / 8pm
- Category:
- Actionscript, Programming
- Tags:
- Post Navigation:
- « The Best Page In The Universe
When You Hit The Proverbial Wall… »