加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex获取url参数的一些写法

发布时间:2020-12-15 04:43:07 所属栏目:百科 来源:网络整理
导读:? 在mxml的application类可以通过geturl获取当前url。获取url可以提供一个很好的方式对swf穿参数。在公司的项目中就大量的应用相关的技术。就和大家分享一下相关的写法,如果写不好就不要笑话哦。 ?? 分析url参数类: package com.sunshine.framework.contro

? 在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;
		}

	}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读