Is there an event that fires when a component is no longer displayed on the screen?

I have a custom component, I designed this part of the panel.

It performs some timer-based polls, which are part of the component.

When the user moves from the view containing this component, I would like to stop the timer and therefore stop the polling.

I can obviously fire an event when the view has changed and catch it inside the component, but I was hoping there might be a way to contain it all inside the component.

Is there an event or a state change inside the component that is triggered even when the component is currently 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> 
+4
source share
3 answers

removedFromStage launched when a component needs to be removed from the scene.

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 removed from the display list, either directly or by deleting an auxiliary tree that contains the display object. Two methods of the DisplayObjectContainer class generate this event: removeChild () and removeChildAt ().

+3
source

EDIT: If you are trying to determine when a user switches between View 1 and View 2 in ViewStack , you can add an event listener to the viewstack1 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 use the visible property of your component to determine whether it is 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> 
0
source

You can use focus events in conjunction with an invisible sprite test that covers the entire stage and / or view / component visiblity (a chain of them may be required).

0
source

Source: https://habr.com/ru/post/1336479/


All Articles