当组件不再显示在屏幕上时是否会触发事件?

发布于 2024-10-13 05:35:24 字数 1055 浏览 3 评论 0原文

我开发了一个自定义组件,它是仪表板的一部分。

它根据作为组件一部分的计时器进行一些轮询。

当用户离开包含此组件的视图时,我想停止计时器,从而停止轮询。

显然,我可以在视图更改时触发一个事件并在组件中捕获它,但我希望可能有一种方法可以将这一切包含在组件中。

即使组件当前正在显示,组件内是否会触发事件或状态更改?

预先感谢您的任何帮助或建议!

例子:

        ]]>
        </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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

七禾 2024-10-20 05:35:24

当组件即将从舞台中删除时,会触发 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

当显示对象即将从显示列表中删除时调度,无论是直接删除还是通过删除包含该显示对象的子树来删除。 DisplayObjectContainer 类的两个方法生成此事件:removeChild() 和removeChildAt()。

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

Dispatched when a display object is about to be removed from the display list, either directly or through the removal of a sub tree in which the display object is contained. Two methods of the DisplayObjectContainer class generate this event: removeChild() and removeChildAt().

网白 2024-10-20 05:35:24

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).

余厌 2024-10-20 05:35:24

编辑:
如果您尝试确定用户何时在 ViewStack 中的 View 1View 2 之间切换,您可以向viewstack1change 事件。

<fx:Script>
  <![CDATA[

    protected function viewstack1_changeHandler(event:IndexChangedEvent):void
    {
      // Do Something
    }

  ]]>
</fx:Script>

<mx:TabBar x="10" y="10" dataProvider="viewstack1" />

<mx:ViewStack x="0" y="0" id="viewstack1" width="675" height="315" change="viewstack1_changeHandler(event);">
  <mx:Canvas label="View 1" width="100%" height="100%">
    <mx:Button x="74" y="69" label="Button 1" width="429" height="185" />
  </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>

如果您使用组件的 visible 属性来确定其是否显示,则还可以在组件中使用 hide 事件处理程序。

<local:MyComponent hide="hideHandler(event)">
  <fx:Script>
    <![CDATA[

    protected function hideHandler(event:FlexEvent):void
    {
      // Do something here.
    }

    ]]>
  </fx:Script>
</local:MyComponent>

EDIT:
If you're trying to determine when the user switches between View 1 and View 2 in your ViewStack, you could add an event listener to the viewstack1's change event.

<fx:Script>
  <![CDATA[

    protected function viewstack1_changeHandler(event:IndexChangedEvent):void
    {
      // Do Something
    }

  ]]>
</fx:Script>

<mx:TabBar x="10" y="10" dataProvider="viewstack1" />

<mx:ViewStack x="0" y="0" id="viewstack1" width="675" height="315" change="viewstack1_changeHandler(event);">
  <mx:Canvas label="View 1" width="100%" height="100%">
    <mx:Button x="74" y="69" label="Button 1" width="429" height="185" />
  </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>

If you're using the visible property of your component to determine if it's displayed or not, you can also use the hide event handler in your component.

<local:MyComponent hide="hideHandler(event)">
  <fx:Script>
    <![CDATA[

    protected function hideHandler(event:FlexEvent):void
    {
      // Do something here.
    }

    ]]>
  </fx:Script>
</local:MyComponent>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文