0

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

<?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'

是否有任何条件我可以检查并确保该对象真的“即将从舞台上移除”?

萨拉姆

4

2 回答 2

0
if( !c1.stage ){
// it is not on stage
}
于 2012-11-26T20:32:45.143 回答
0

removedFromStage在项目从舞台上移除之前被调用。如果您在该事件处理程序中不执行任何操作,则该元素将被删除。

于 2012-11-25T18:00:47.330 回答