Flex中弹出对话框的定制

package com.fangjixiang.myControls

{

    import flash.external.ExternalInterface;   

    import mx.controls.Alert;

    import mx.core.UIComponent;

    import mx.events.CloseEvent;

 

    publicclass AlertBoxFunc

    {  

       /*

       * @ 弹出提示框

       * lanauage        语文类型,默认英文,CN为中文

       * msg             对话框内内容

       * title           对话框标题    

       */            

       publicstaticfunction AlertBox(language:String,msg:String,title:String):void

        {

            Alert.okLabel = "OK";

            if(language == "CN")

            {

               Alert.okLabel = "确定";                        

            }

            var alert:Alert = Alert.show(msg,title);

            var scrollTopNum:int=ExternalInterface.call("getTopPosion");          

            alert.validateNow();             

            alert.y=scrollTopNum;

       

       }

       /*

       *   @弹出询问框

       * lanauage        语文类型,默认英文,CN为中文

       * msg             对话框内内容

       * title           对话框标题

       * successFunc     确认后执行的方法

       * successParams   确认后执行的方法参数

       * failFunc        否认后执行的方法

       * failParams      否人后执行的方法参数

       */     

       publicstaticfunction confirmBox(windows:UIComponent,language:String,msg:String,title:String,successFunc:Function,successParams:Array,failFunc:Function=null,failParams:Array=null):void

    {

           Alert.yesLabel = "Yes";

           Alert.noLabel =  "No";         

           if(language == "CN")

           {

              Alert.yesLabel = "";

              Alert.noLabel =  "";          

           }  

         

             var alert:Alert = Alert.show(msg,title, Alert.YES|Alert.NO, windows,

              function(evt:CloseEvent):void

              {

                  if(evt.detail == Alert.YES)

                  {

                    if(successFunc!=null) successFunc.apply(windows,successParams);

                  }

                  else

                  {

                       if(failFunc!=null) failFunc.apply(windows,failParams);

                  }

              },null, Alert.YES);

          

           var scrollTopNum:int=ExternalInterface.call("getTopPosion");

           alert.validateNow();             

           alert.y=scrollTopNum;

       }

       /*

       *  @弹出带取消的询问框

       * lanauage      语文类型,默认英文,CN为中文

       * msg           对话框内内容

       * title         对话框标题

       * successFunc   确认后执行的方法

       * successParams 确认后执行的方法参数

       * failFunc      否认后执行的方法

       * failParams    否人后执行的方法参数

       * cancelFunc    取消后执行的方法

       * canceParams   取消手执行的方法参数

       */

       publicstaticfunction confirmCancelBox(windows:UIComponent,language:String,msg:String,title:String,successFunc:Function,successParams:Array,failFunc:Function=null,failParams:Array=null,cancelFunc:Function=null,canceParams:Array = null):void

    {

           Alert.yesLabel = "Yes";

           Alert.noLabel =  "No";

           Alert.cancelLabel  = "Cancel";

           if(language == "CN")

           {

              Alert.yesLabel = "";

              Alert.noLabel =  "";

              Alert.cancelLabel  = "取消";

           }          

        //Alert.show(

            var alert:Alert = Alert.show(msg,title, Alert.YES|Alert.NO|Alert.CANCEL, windows,

              function(evt:CloseEvent):void

              {

                   if(evt.detail == Alert.YES)

                   {

                   if(successFunc!=null) successFunc.apply(windows,successParams);

                   }

                   elseif (evt.detail == Alert.CANCEL)

                   {

                      if (cancelFunc != null) cancelFunc.apply(windows,canceParams);

                   }

                   else

                   {

                      if(failFunc!=null) failFunc.apply(windows,failParams);

                   }

              },null, Alert.YES);

           var scrollTopNum:int=ExternalInterface.call("getTopPosion");

           alert.validateNow();             

           alert.y=scrollTopNum;

       }

    }

 

}

注意:

  AlertBox为弹出一个警告框或者提示框.
 confirmBox为弹出一个Yes or No的提示框.
 confirmCancelBox同样也是弹出一个Yes or No的提示狂,不同的是它还带取消按钮.

其中每个方法里有一句话:var scrollTopNum:int=ExternalInterface.call("getTopPosion");这是防止当前画布太大,当HTML页面有滚动条时取得滚动条的纵坐标,即根据客户端来判断弹出的对话框在什么位置.getTopPosion是客户端JS方法,如下:

function getTopPosion()

{

     var scrollPos=0;

     if (typeof window.pageYOffset != 'undefined')

     {

        scrollPos = window.pageYOffset;

     }

     else if(typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')

     {

        scrollPos = document.documentElement.scrollTop;

     }

     else if (typeof document.body != 'undefined')

     {

        scrollPos = document.body.scrollTop;

     }

     return scrollPos;

 }

调用时将JS方法写在HTML中,然后flex中import com.fangjixiang.myControls.AlertBoxFunc;

代码:

(1)、AlertBoxFunc.AlertBox(”CN”,”content”,”title”);

(2)、var params:Array = [event]; 
var arrayNull:Array = null;
   
AlertBoxFunc.confirmCancelBox(this,"CN","确认降低房价吗?","确认对话框",sussFun,params,failFun,params,cancelfunc,arrayNull);
其中sussFun为点确认后执行的方法.failFun为点否后执行的方法.cancelfunc为点取消后执行的方法.

(3)、AlertBoxFunc.confirmBoxthis,"CN","确认降低房价吗?","确认对话框",sussFun,params,failFun,params);          

posted @ 2016-05-17 10:43  lovemx  阅读(337)  评论(0)    收藏  举报