Flex4读取cookie

利用附件中的Cookie.as文件包,可以方便的读写取cookie信息。注意的读取cookie是由其它页面写入的情况,要保证这个页面的域名相同,新建一个system包,将Cookie.as放入。

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
	
	<fx:Script>
		<![CDATA[
			import system.Cookie;
			protected function button1_clickHandler(event:MouseEvent):void
			{
				readCookie();
				
			}
			
			protected function readCookie():void {			
				var cookie:Object = Cookie.getCookie("username");
				if (cookie == null) {						
					txtArea.text = "读取失败";
				}
				else {						
					txtArea.text = decodeURI(cookie.toString());
				}
			}
		]]>
	</fx:Script>
	
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<s:Button x="194" y="209" label="readcookie" click="button1_clickHandler(event)"/>
	<s:Label x="194" y="258" text="读取结果:"/>
	<s:TextArea id="txtArea" x="284" y="258"/>
</s:Application>

 

你可能感兴趣的:(cookie flex4 域名)