我有一个空气应用程序,点击时有一个按钮打开一个新的spark.window组件。在窗口中是一个视频播放器。新的secondWindow.open()方法工作正常。当父窗口关闭时,我似乎无法做的就是关闭第二个窗口。
我有这个:
//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>
答案 0 :(得分:0)
主要应用:
<?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>
子窗口(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>