当组件不再显示在屏幕上时是否会触发事件?
我开发了一个自定义组件,它是仪表板的一部分。
它根据作为组件一部分的计时器进行一些轮询。
当用户离开包含此组件的视图时,我想停止计时器,从而停止轮询。
显然,我可以在视图更改时触发一个事件并在组件中捕获它,但我希望可能有一种方法可以将这一切包含在组件中。
即使组件当前正在显示,组件内是否会触发事件或状态更改?
预先感谢您的任何帮助或建议!
例子:
]]>
</mx:Script>
<mx:TabBar x="10" y="10" dataProvider="viewstack1">
</mx:TabBar>
<mx:ViewStack x="0" y="0" id="viewstack1" width="675" height="315">
<mx:Canvas label="View 1" width="100%" height="100%">
<mx:Button x="74" y="69" label="Button 1" width="429" height="185" removedFromStage="removeFromStageEvent()"/>
</mx:Canvas>
<mx:Canvas label="View 2" width="100%" height="100%">
<mx:Button x="74" y="69" label="Button 2" width="429" height="185" color="red"/>
</mx:Canvas>
</mx:ViewStack>
</mx:Application>
I have a custom component I've developed that's part of a dashboard.
It does some polling based on a timer that's part of the component.
When the user navigates away from the view that contains this component I would like to stop the timer and hence stop the polling.
I can obviously fire an event when the view's changed and catch it within the component but I was hoping that there might be a way to contain this all within the component.
Is there an event or state change within a component that triggers and even when a component is currently be displayed?
Thanks in advance for any help or suggestions!
Example:
]]>
</mx:Script>
<mx:TabBar x="10" y="10" dataProvider="viewstack1">
</mx:TabBar>
<mx:ViewStack x="0" y="0" id="viewstack1" width="675" height="315">
<mx:Canvas label="View 1" width="100%" height="100%">
<mx:Button x="74" y="69" label="Button 1" width="429" height="185" removedFromStage="removeFromStageEvent()"/>
</mx:Canvas>
<mx:Canvas label="View 2" width="100%" height="100%">
<mx:Button x="74" y="69" label="Button 2" width="429" height="185" color="red"/>
</mx:Canvas>
</mx:ViewStack>
</mx:Application>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当组件即将从舞台中删除时,会触发
removedFromStage
。http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/Event.html?filter_flex=4.1&filter_flashplayer=10.1&filter_air=2#REMOVED_FROM_STAGE
removedFromStage
is triggered when a component is about to be removed from the stage.http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/Event.html?filter_flex=4.1&filter_flashplayer=10.1&filter_air=2#REMOVED_FROM_STAGE
您也许可以使用焦点事件 结合覆盖整个舞台和/或视图/组件可见性的不可见精灵的命中测试(可能需要一系列这些)。
You may be able to use the focus events in combination with a hit test of an invisible sprite that covers the whole stage and/or the view/component visiblity (may need a chain of these).
编辑:
如果您尝试确定用户何时在
ViewStack
中的View 1
和View 2
之间切换,您可以向viewstack1
的change
事件。如果您使用组件的
visible
属性来确定其是否显示,则还可以在组件中使用hide
事件处理程序。EDIT:
If you're trying to determine when the user switches between
View 1
andView 2
in yourViewStack
, you could add an event listener to theviewstack1
'schange
event.If you're using the
visible
property of your component to determine if it's displayed or not, you can also use thehide
event handler in your component.