0

我试图将警报框限制为特定模块,它不应该超出模块范围。我保留了 2 个选项卡,每个选项卡都包含不同的模块。但是警报的范围是全球性的,它影响的是整个窗口,而不是仅限于模块区域。请看下面的代码。

主.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
    <![CDATA[
          import mx.modules.*;

         public function createModule(m:ModuleLoader, s:String):void {
        if (!m.url) {
            m.url = s;
            return;
        }
        m.loadModule();
    }

    public function removeModule(m:ModuleLoader):void {
        m.unloadModule();
    }


    ]]>
</mx:Script>
 <mx:Panel title="Module Example" 
    height="90%" 
    width="90%" 
    paddingTop="10" 
    paddingLeft="10" 
    paddingRight="10" 
    paddingBottom="10"
 >
    <mx:TabNavigator id="tn" 
        width="100%" 
        height="100%" 
        creationPolicy="auto">
        <mx:VBox id="vb1" label="Column Chart Module">                
            <mx:Button 
                label="Load"   click="createModule(chartModuleLoader, l1.text)"/>
            <mx:Button 
                label="Unload" />
            <mx:Label id="l1" text="module1.swf"/>
            <mx:ModuleLoader id="chartModuleLoader"/>                                
        </mx:VBox>

        <mx:VBox id="vb2" label="Form Module">
            <mx:Button 
                label="Load"    click="createModule(formModuleLoader, l2.text)"/>
            <mx:Button 
                label="Unload"/>
            <mx:Label id="l2" text="module2.swf"/>
            <mx:ModuleLoader id="formModuleLoader"/>
        </mx:VBox>
    </mx:TabNavigator>
</mx:Panel>
</mx:Application>

模块1.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400"    height="300">
<mx:Button label="Click 1 " click="ini()"/>
<mx:Script>
    <![CDATA[
        import mx.controls.Alert;

        public function ini():void
        {
            Alert.show("How","hello", 0,null,null,null,0);
        }

    ]]>
</mx:Script>
</mx:Module>

模块2.mxml

 <?xml version="1.0" encoding="utf-8"?>
 <mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300">
<mx:Button label="Click 2 " click="ini1()"/>
<mx:Script>
    <![CDATA[
        import mx.controls.Alert;

        public function ini1():void
        {
            Alert.show("Click 2","hello", 0,this);
        }

    ]]>
</mx:Script>
 </mx:Module>

谢谢你

4

1 回答 1

0

根据我的评论,您尝试的方法是行不通的。但是这是一种实现方法:

在每个可以显示警报的模块中:

private function createAlert(text:String):void{
    var myAlert:Alert = new Alert();
    myAlert.addEventListener(CloseEvent.CLOSE, onClose);
    myAlert.title = "Attention";
    myAlert.label = text;
    alertLayer.addElement(myAlert);
}

private function onClose(event:CloseEvent):void{
    trace("closed");
}

然后在模块 mxml

<s:VGroup id="alertLayer" width="100%" height="100%" verticalAlign="middle" horizontalAlign="center" />

这将强制在模块的最顶层发出警报,而不使用 PopUpManager 或全局范围。这更像是你所追求的吗?

于 2013-01-08T15:35:42.917 回答