I am using a TabbedViewNavigatorApplication, and when switching tabs I need video to stop playing. I've looked at the spark video player source code and adapted a function from it that assigns event listeners to all the parents. This code works fine on the current view, but if I switch tabs or go back a view, it does not work... the FlexEvent.Hide listeners don't fire. In the debugger I have verified that the below code does indeed assign the listeners all the way up the parent chain, so I am wondering if either the views are not getting destroyed or I am not using the right listeners. Does anyone know?
* Add event listeners for SHOW and HIDE on all the ancestors up the parent chain.
* Adding weak event listeners just to be safe.
private function addVisibilityListeners():void
var current:IVisualElement = this;
// add visibility listeners to the parent
current.addEventListener(FlexEvent.HIDE, visibilityChangedHandler, false, 0, true);
current.addEventListener(FlexEvent.SHOW, visibilityChangedHandler, false, 0, true);
// add listeners to the design layer too
current.designLayer.addEventListener("layerPropertyChange", designLayer_layerPropertyChangeHandler, false, 0, true);
current = current.parent as IVisualElement;
I figured this out. When the views are switched, the old view is removed from the stage, therefore the visibility change handler was never getting fired. Solved this by adding a removed from stage event to the video player code to stop it playing.