在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; } } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。