SharedObject简单的说就是flash的cookie,用于在本地存储一些数据。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
[Bindable]
public var myName:String;
public function getName():String
{
var object:SharedObject = SharedObject.getLocal("userinfo");
return object.data.myName;
}
public function setName(myName:String):void
{
var object:SharedObject = SharedObject.getLocal("userinfo");
object.data.myName = myName;
Alert.show("Your data was saved locally", "Confirmation");
}
]]>
</mx:Script>
<mx:Panel title="Enter Data">
<mx:Form>
<mx:FormItem label="Your Name:">
<mx:TextInput id="nameInput"/>
</mx:FormItem>
<mx:FormItem>
<mx:Button label="Save" click="setName(nameInput.text)"/>
</mx:FormItem>
<mx:FormItem>
<mx:Button label="Get" click="myName=getName()"/>
<mx:Label text="{myName}" fontSize="14"/>
</mx:FormItem>
</mx:Form>
</mx:Panel>
</mx:Application> |