Reputation: 1
I'm following this tutorial which is great but I can't understand why he puts an ADDED_TO_STAGE event in the constructor function of every class he creates. If you put that code directly on the constructor function it runs ok. Is there some reason to make it that way?
package pantallas
{
public class Menu extends Sprite
{
public function Menu()
{
super();
this.addEventListener(starling.events.Event.ADDED_TO_STAGE, iniciarMenu);
}
private function iniciarMenu (event:Event):void
{
trace ("Menú iniciado");
dibujarPant ();
}
}
}
VS
package pantallas
{
public class Menu extends Sprite
{
public function Menu()
{
trace ("Menú iniciado");
dibujarPant ();
}
}
}
Upvotes: 0
Views: 143
Reputation: 911
because, you can ran into some errors if you execute the code, and content is not on stage. This way you are certain.
for example, when DisplayObject is added to stage, your parent and stage properties are not null
Upvotes: 0