简体   繁体   中英

Restrict Alertbox/Pop-up to inidvdual module in flex 3

I am trying to restrict a Alert-box to a specific module, it should not scope outside the module. I have kept to 2 tabs containing different modules in each. But the scope of alert is being global, and it is effecting the whole window other than limiting to the module area. Please look at below code.

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>

Thank You

Per my comment, what you were trying wouldn't work.. but here is a way to accomplish it:

in each module that can display an alert:

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");
}

then in the module mxml

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

This will force the alert in the topmost layer of the module without using PopUpManager or global scope at all. Is this more of what you were after?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM