Flex 4 空气关闭第二个窗口

发布于 2025-01-01 10:48:42 字数 1103 浏览 2 评论 0原文

我有一个空气应用程序,有一个按钮,单击时会打开一个新的 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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

蓝海 2025-01-08 10:48:42

主要应用:

<?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>

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