Skip to main content
Participating Frequently
August 16, 2010
Question

ADDED event in document class after removed from Stage

  • August 16, 2010
  • 2 replies
  • 1242 views

Hi All,

I am currently play with the document class (the class acts as main) constructor for a SWF file.

package {

  import flash.display.*;

  import flash.events.*;

  public class TestSymbol extends MovieClip

  {

    public function TestSymbol()

    {

      this.addEventListener(Event.ADDED, function(event:Event) { trace(event.eventPhase, event.target, event.currentTarget, "added triggered"); });

      trace("parent", this.parent);

      this.stage.removeChild(this);

      trace("stage", this.stage);

    }

  }

}

In frame script 1, i put

trace("1");

trace("parent", this.parent);

After i run TestSymbol.swf and  i got

parent [object Stage]

stage null

2 [object TestSymbol] [object TestSymbol] added triggered

1

parent null

I wonder where is this ADDED event coming from? If the document class is added to some other objects, why its parent is null after the event?

Thanks in advance

Sam

This topic has been closed for replies.

2 replies

Inspiring
August 16, 2010

Oh, and never use anonymous functions, especially as event handlers - it is a very bad and dangerous practice.

Inspiring
August 16, 2010

I wonder where is this ADDED event coming from?

You added Event.ADDED event listener - this is where it comes from.

If the document class is added to some other objects, why its parent is null after the event?

Because you remove the object as a stage child (removeChild) - so it is null.

Participating Frequently
August 17, 2010

Thanks for the reply, sorry for the wrong question i asked. the ADDED event is dispatched when it is added to the display list, but i can't see there are any add operation here, so i am wondering is there any hidden add operation behind the scene?

And thanks for your suggestion, i will keep an eye on it.