检测对象何时从舞台上移除

时间:2012-11-25 17:09:33

标签: actionscript-3 flex flex3

我想检测对象是否已从舞台中删除。我在这里和其他地方检查了很多答案。不知道如何被注意到对象真的被从舞台上移除(我的意思是它不再显示在舞台上)。 下面的代码是我的最后一次测试:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Canvas width="100%" height="50%" backgroundColor="gray" id="c1">
        <mx:Canvas id="cChild" backgroundColor="black" width="20" height="20" 
        left="20" top="20" 
        removedFromStage="trace('removed from stage ' + event.target)" 
        removed="trace('removed ' + event.target)">
        </mx:Canvas>
    </mx:Canvas>
    <mx:Canvas width="100%" height="50%" backgroundColor="white"  id="c2">
    </mx:Canvas>
    <mx:Button label="add child" click="c2.addChild(c1)" />
    <mx:Button label="add child2" click="addChild(c1)" />
</mx:Application>

我不明白我在控制台输出中发现了什么:

removed MainFlex0.c1.cChild.border
  - before click 'add child'
removed from stage MainFlex0.c1.cChild
removed MainFlex0.c2.c1.cChild.border
  - after click 'add child', before 'add child2'
removed from stage MainFlex0.c2.c1.cChild
removed MainFlex0.c1.cChild.border
  - after click 'add child2'

我可以检查任何条件,并确保该对象真的“即将从舞台上删除”吗?

德萨兰

2 个答案:

答案 0 :(得分:0)

在从舞台中删除项目之前调用

removedFromStage。如果您在该事件处理程序中没有执行任何操作,则将删除该元素。

答案 1 :(得分:0)

if( !c1.stage ){
// it is not on stage
}
相关问题