flex获取url参数的一些写法

               

   在mxml的application类可以通过geturl获取当前url。获取url可以提供一个很好的方式对swf穿参数。在公司的项目中就大量的应用相关的技术。就和大家分享一下相关的写法,如果写不好就不要笑话哦。

   分析url参数类:

   package com.sunshine.framework.control{ import com.sunshine.framework.model.UrlParameters; import com.sunshine.framework.util.UrlParametersArrayCollection; public class GetUrlParameters {  private var _url:String;  private var urlParamenters:UrlParameters;  private var _resultList:UrlParametersArrayCollection=new UrlParametersArrayCollection;  public function GetUrlParameters()  {  }  public function analysisParameters(value:String=null):UrlParametersArrayCollection  {   if (value != null)   {    this._url=value;    var num:int=_url.indexOf("?");    var parametersUrl:String=_url.substring(num + 1);    var parameters:Array=parametersUrl.split(/&/);    for (var i:int=0; i < parameters.length; i++)    {     var parameter:Array=String(parameters[i]).split(/=/);     urlParamenters=new UrlParameters;     urlParamenters.prarameterName=parameter[0];     urlParamenters.prarameter=parameter[1];     _resultList.addParametersModel(urlParamenters);    }   }   return _resultList;  }  public function set url(value:String):void  {   this._url=value;  }  public function get url():String  {   return _url;  }  public function set resultList(value:UrlParametersArrayCollection):void  {   this._resultList=value;  }  public function get resultList():UrlParametersArrayCollection  {   return _resultList;  } }}

 

  url参数的model:

  package com.sunshine.framework.model{ public class UrlParameters {  private var _prarameterName:String;  private var _prarameter:String;  public function UrlParameters()  {  }  public function set prarameterName(value:String):void  {   this._prarameterName=value;  }  public function get prarameterName():String  {   return _prarameterName;  }  public function set prarameter(value:String):void  {   this._prarameter=value;  }  public function get prarameter():String  {   return _prarameter;  } }}

 

  url参数的容器:

 package com.sunshine.framework.util{ import com.sunshine.framework.model.UrlParameters; import mx.collections.ArrayCollection; import mx.controls.Alert; public class UrlParametersArrayCollection extends ArrayCollection {  private var urlParamenters:UrlParameters;  public function UrlParametersArrayCollection(source:Array=null)  {   super(source);  }  public function addParametersModel(value:UrlParameters):void  {   var name:String=value.prarameterName;   var parameter:String=value.prarameter;   var b:Boolean=true;   if (this.length != 0)   {    for (var i:int=0; i < this.length; i++)    {     urlParamenters=this.getItemAt(i) as UrlParameters;     if (name == urlParamenters.prarameterName)     {      (this.getItemAt(i) as UrlParameters).prarameter=parameter;      b=false;     }    }    if (b == true)    {     var urlParamenters:UrlParameters=new UrlParameters;     urlParamenters.prarameterName=name;     urlParamenters.prarameter=parameter;     this.addItem(urlParamenters);    }   }   else   {    var urlParamenters:UrlParameters=new UrlParameters;    urlParamenters.prarameterName=name;    urlParamenters.prarameter=parameter;    this.addItem(urlParamenters);   }  }  public function addParameters(name:String, parameter:String):void  {   var b:Boolean=true;   if (this.length != 0)   {    for (var i:int=0; i < this.length; i++)    {     urlParamenters=this.getItemAt(i) as UrlParameters;     if (name == urlParamenters.prarameterName)     {      (this.getItemAt(i) as UrlParameters).prarameter=parameter;      b=false;     }    }    if (b == true)    {     var urlParamenters:UrlParameters=new UrlParameters;     urlParamenters.prarameterName=name;     urlParamenters.prarameter=parameter;     this.addItem(urlParamenters);    }   }   else   {    var urlParamenters:UrlParameters=new UrlParameters;    urlParamenters.prarameterName=name;    urlParamenters.prarameter=parameter;    this.addItem(urlParamenters);   }  }  public function getParameters(name:String):String  {   var parameters:String="";   if (this.length != 0)   {    for (var i:int=0; i < this.length; i++)    {     urlParamenters=this.getItemAt(i) as UrlParameters;     if (name == urlParamenters.prarameterName)     {      parameters=urlParamenters.prarameter;     }    }    return parameters;   }   else   {    return parameters;   }  }  public function getHandleDataXmlUrl():String  {   var url:String=getParameters("dataUrl");   var handleUrl:String="";   var re:RegExp=/#/;   var results:Array=url.split(re);   for (var i:int=0; i < results.length; i++)   {    if (i % 2 != 0)    {     handleUrl=handleUrl + getParameters(results[i]);    }    else    {     handleUrl=handleUrl + results[i];    }   }   return handleUrl;  } }}

 

           
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值