0

一个月以来,我一直致力于创建一个自定义对话框,具有消息、状态和模态(true/false)等参数

例如:

showAlert("Hi, how are you doing","Goodmorning", true);

我已经学会了如何调度事件。但无法使用状态调度 alertevent/popupManager。下面是代码,我正在努力。

主.mxml

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

    public function onclick(event:MouseEvent):void
    {
    this.dispatchEvent("Hi, How are you?", "Morning", true);
    }
     public function dispatchEvent(arg1:String, arg2:String, arg3:Boolean):void
    {
        var str:*=null;
        str.message = arg1;
        str.stateName = arg2;
        str.modal = arg3;
        this.dispatchEvent(new ShowAlert(ShowAlert.SHOW, true));
    }

]]>
  </mx:Script>  
  <mx:Button id="click" click="onclick(event)"/>
  </mx:Application>

ShowAlert.as

package 
{
import flash.events.*;

public class ShowAlert extends Event
{

    public var _stateName:String;

    public var _closable:Boolean;

    public var _message:String;

    public var _isModal:Boolean;
    public static const SHOW:String="show";


    public function flash.events.(arg1:String, arg2:Boolean=false, arg3:Boolean=false)
    {
        super(arg1, arg2, arg3);
        trace("arg1: "+arg1+"\t arg2: "+arg2+"\t arg3: "+arg3);

    }

    public function set message(arg1:String):void
    {
        this._message = arg1;

    }


    public function get message():String
    {
        return _message;
    }


    public function get modal():Boolean
    {
        return _isModal;
    }


    public function get stateName():String
    {
        return _stateName;
    }

    public function set stateName(arg1:String):void
    {
        this._stateName = arg1;

    }




          public function set modal(arg1:Boolean):void
    {
        this._isModal = arg1;

    }

    public override function clone():flash.events.Event
    {
        return new ShowAlert(type);
    }


 }
 }

我无法使用状态编写自定义标题窗口,所以我尽力发布。

请让我知道,如何做到这一点。

下面是示例代码,指定我的问题

主.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.controls.Alert;
public var info:IModuleInfo;
public var loadalert:DisplayObject;
import mx.modules.ModuleManager;
    import mx.modules.IModuleInfo;
    import mx.events.ModuleEvent;
    public function init():void
    {
        Alert.show("This is forst alert.");

    }
    public function Loadalerrt():void
    {
        trace("loadalertmodule");
        info = ModuleManager.getModule("../bin-debug/alerrtmod.swf");
        info.addEventListener(ModuleEvent.READY, modEventHandler); 
        info.load();

    }
    public function modEventHandler(event:ModuleEvent):void
    {
        trace("modeventHandler");
    loadalert=info.factory.create() as DisplayObject;
    can1.addChild(loadalert);

    }
]]>
 </mx:Script>
<mx:Button label="Alert in Application" id="b1" click="init()" x="29" y="21"/>
<mx:Button label="Load Module" id="b2" click="Loadalerrt();" x="10" y="92"/>
<mx:Canvas id="can1"  x="409" y="57" backgroundColor="cyan"/>
</mx:Application>

alerttmod.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:Script>
<![CDATA[
import mx.controls.Alert;
    public function alertshow():void
    {
        Alert.show("This is second alert, You Can see it covers whole   application, What I want is its scope should be limited to this specific module, not to whole application ");
    }
]]>
</mx:Script>
<mx:Button label="Alert in Module" id="b1" click="alertshow()" x="163" y="100"/>
</mx:Module>
4

1 回答 1

0

现在我看到了你的问题。我认为不可能限制警报的模态区域。我可以建议您通过在显示对话框时禁用模块元素来伪造模态行为。

也许它可以帮助你...

这里有两个组件来演示它:

//你的模块有另一个警报

<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400"   height="300">
<mx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.managers.PopUpManager;

        public function alertshow():void
        {
            Alert.show("This is second alert...");
        }

        public function alertshow2():void
        {
            var customAlert:CustomAlert = new CustomAlert();
            customAlert.addEventListener("CLOSED", onCustomAlertClosed);
            this.enabled = false;

            PopUpManager.addPopUp(customAlert, this, false);
            PopUpManager.centerPopUp(customAlert);
        }

        private function onCustomAlertClosed(evt:Event):void
        {
            this.enabled = true;
        }
    ]]>
</mx:Script>
<mx:Button label="Alert in Module" id="b1" click="alertshow()" x="163" y="100"/>

<mx:Button label="CustomAlert in Module" id="b2" click="alertshow2()" x="163" y="150"/>

<mx:Canvas width="100%" height="100%" backgroundColor="0xbbbbbb" alpha="0.8" visible="{!this.enabled}"/>

</mx:Module>

//简单的CustomAlert作为面板

<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="300" height="200">
<mx:Script>
    <![CDATA[
        import mx.managers.PopUpManager;

        protected function button1_clickHandler(event:MouseEvent):void
        {
            PopUpManager.removePopUp(this);
            this.dispatchEvent(new Event("CLOSED"));
        }
    ]]>
</mx:Script>
<mx:Button x="112" y="128" label="Close" click="button1_clickHandler(event)"/>
</mx:Panel>
于 2013-03-04T12:06:13.573 回答