forked from: What's wrong with ADDED_TO_STAGE?
forked from What's wrong with ADDED_TO_STAGE? (diff: 4)
What's wrong with ADDED_TO_STAGE? I'm expexcting to get this: lvl1 added to stage lvl2 added to stage lvl3 added to stage but I don't... ADDED_TO_STAGE gets fired several time without trigerring REMOVED_FROM_STAGE... Am I missing something? 気になる
ActionScript3 source code
/**
* Copyright nki2 ( http://wonderfl.net/user/nki2 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/Arqn
*/
// forked from nki2's What's wrong with ADDED_TO_STAGE?
/*
What's wrong with ADDED_TO_STAGE?
I'm expexcting to get this:
lvl1 added to stage
lvl2 added to stage
lvl3 added to stage
but I don't...
ADDED_TO_STAGE gets fired several time without trigerring REMOVED_FROM_STAGE...
Am I missing something?
気になる
*/
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
[SWF(backgroundColor="0xf0f5e0", frameRate="30", width="465", height="465")]
public class Index extends Sprite {
public static var txt:TextField;
//----------------------------------------------------------------------------------------------------
/// init
public function Index() {
txt = addChild(new TextField()) as TextField;
txt.defaultTextFormat = new TextFormat(null, 26);
txt.width = 465;
txt.height = 465;
//
var lvl3:MySprite = new MySprite("lvl3");
var lvl2:MySprite = new MySprite("lvl2", lvl3);
var lvl1:MySprite = new MySprite("lvl1", lvl2);
addChild(lvl1);
log("\n\n => OK...");
}
public static function log(str:String):void {
txt.appendText(str + "\n");
}
}
}
import flash.display.Sprite;
import flash.events.Event;
internal class MySprite extends Sprite {
public function MySprite(name:String, futureChild:Sprite = null) {
if(futureChild) addChild(futureChild);
addEventListener(Event.ADDED_TO_STAGE, function(e:Event):void {
Index.log(name + " added to stage");
});
addEventListener(Event.REMOVED_FROM_STAGE, function(e:Event):void {
Index.log(name + " removed from stage");
});
}
}
