0

アラートボックスを特定のモジュールに制限しようとしていますが、モジュールの外部をスコープするべきではありません。それぞれに異なるモジュールを含む2つのタブを保持しました。ただし、アラートの範囲はグローバルであり、モジュール領域に限定する以外はウィンドウ全体に影響を及ぼします。以下のコードをご覧ください。

main.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>

Module1.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>

Module2.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 に答える