Consider this simple AS3 class.
package
{
import flash.display.Sprite;
import flash.display.MovieClip;
public class MySprite extends Sprite
{
private var someMC:MovieClip = new MovieClip();
public function MySprite()
{
super();
addChild(someMC);
}
}
}
And this one:
package
{
import flash.display.Sprite;
import flash.display.MovieClip;
public class MySprite extends Sprite
{
private var someMC:MovieClip;
public function MySprite()
{
super();
someMC = new MovieClip();
addChild(someMC);
}
}
}
Is this the same thing, or is there more to it?
I guess its because in the first example, the MovieClip seems to exist before the contructor is called (when does this occur, what is the benefit or not?).
It’s all the same. The compiler translates your first example into the second. The only difference is that you can control instantiation order when you put the assignment into the constructor.