i have an air application that has a button when clicked opens a new spark.window component. in the window is a video player. the new secondWindow.open() method works fine. what i can't seem to do is close the second window when the parent window closes.
i have this:
//parent window
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="733" minHeight="653" creationComplete="main()" currentState="loginForm" applicationDeactivate="windowedapplication1_applicationDeactivateHandler(event)">
//close second window
protected function windowedapplication1_applicationDeactivateHandler(event:Event):void{
NativeApplication.nativeApplication.openedWindows[0].close();
}
</s:WindowedApplication>
//second window
<s:Window name="secondWindow" xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="450" minHeight="323" windowComplete="init()">
//video player code is here
</s:Window>
Main application:
<?xml version="1.0"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
width="100%" height="100%"
creationComplete="_creationComplete()"
closing="_closingHandler(event)">
<fx:Script><![CDATA[
private var _testWindow:TestWindow;
private function _creationComplete():void
{
butt.addEventListener(MouseEvent.CLICK, _butt_clickHandler);
}
private function _butt_clickHandler(event:MouseEvent):void
{
if(_testWindow)
{
return;
}
_testWindow = new TestWindow();
_testWindow.open();
}
private function _closingHandler(event:Event):void
{
var openedWindows:Array = nativeApplication.openedWindows;
var i:uint;
var count:uint = openedWindows.length;
for(i; i < count; i++)
{
openedWindows[i].close();
}
}
]]></fx:Script>
<s:Button id="butt" label="Open"/>
</s:WindowedApplication>
Child window (TestWindow.mxml):
<?xml version="1.0"?>
<s:Window xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
width="300" height="300">
<s:Label text="Test Window" />
</s:Window>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.