1

我正在实现一个标题窗口,它像这样从主应用程序调用

protected function sampleButton_clickHandler(event:MouseEvent):void
            {
                var ttlWndw:SampleTitleWindow = PopUpManager.createPopUp(FlexGlobals.topLevelApplication as DisplayObject, SampleTitleWindow, true) as SampleTitleWindow;
                PopUpManager.centerPopUp(ttlWndw);
            }

标题窗口将是这个

<?xml version="1.0" encoding="utf-8"?>
<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               xmlns:local="*"
               width="288" height="230">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <local:SampleVBox id="sampleVBox" x="108" y="83"/>
</s:TitleWindow>

在标题窗口中,我有另一个名为 sample vbox 的子组件,这个组件看起来像这样

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx">

    <fx:Script>
        <![CDATA[
            protected function closeBtn_clickHandler(event:MouseEvent):void
            {

            }
        ]]>
    </fx:Script>


    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Button id="closeBtn" label="Close" click="closeBtn_clickHandler(event)"/>
</mx:VBox>

我的问题是,我想使用 sampleVBox 组件中的按钮关闭标题窗口。请有人帮助我。

提前致谢!

4

1 回答 1

1

一种解决方案是从父级将要侦听的SampleVBox组件中分派一个事件。TitleWindow为此,请向您的SampleVBox类添加一些元数据,以指示该类调度此类事件:

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx">

    <fx:Metadata> 
        [Event(name="close", type="flash.events.Event")] 
    </fx:Metadata> 

    <fx:Script>
        <![CDATA[
            protected function closeBtn_clickHandler(event:MouseEvent):void
            {
                dispatchEvent(new Event(Event.CLOSE));
            }
        ]]>
    </fx:Script>

    <s:Button id="closeBtn" label="Close" click="closeBtn_clickHandler(event)"/>
</mx:VBox>

现在,SampleVBox声明它调度了一个“关闭”事件,您可以在以下位置监听它TitleWindow

<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               xmlns:local="*"
               width="288" height="230">

    <fx:Script>
        <![CDATA[
            protected function onSampleBoxClose():void
            {
                PopUpManager.removePopUp(this);
            }
        ]]>
    </fx:Script>

    <local:SampleVBox id="sampleVBox" x="108" y="83" close="onSampleBoxClose()"/>
</s:TitleWindow>
于 2013-07-14T23:47:34.243 回答