<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
width="400" height="300" viewSourceURL="srcview/index.html" creationComplete="init();">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
[Bindable]
private var user:SharedObject = SharedObject.getLocal("user");
private function init():void{
if(user.data.firstName!=undefined){
myFirstName.text=user.data.firstName;
}
if(user.data.lastName!=undefined){
myLastName.text=user.data.lastName;
}
if(user.data.emailAddress!=undefined){
myEmail.text=user.data.emailAddress;
}
}
private function saveObject():void
{
user.data.firstName = myFirstName.text;
user.data.lastName = myLastName.text;
user.data.emailAddress= myEmail.text;
user.flush(500);
Alert.show("Data has been Saved, Refresh the browser to see");
}
private function clearObject():void
{
user.clear();
Alert.show("Shared Object Cleared");
}
]]>
</mx:Script>
<mx:Panel title="Shared Object Example">
<mx:Form>
<mx:FormItem label="First Name">
<mx:TextInput id="myFirstName" text="{user.data.firstName}"/>
</mx:FormItem>
<mx:FormItem label="Last Name">
<mx:TextInput id="myLastName" text="{user.data.lastName}"/>
</mx:FormItem>
<mx:FormItem label="Email Address">
<mx:TextInput id="myEmail" text="{user.data.emailAddress}"/>
</mx:FormItem>
</mx:Form>
<mx:ControlBar>
<mx:Button label="Save" click="saveObject()"/>
<mx:Button label="Clear Shared Object" click="clearObject()"/>
</mx:ControlBar>
</mx:Panel>
</mx:Application>
存储数据到共享对象
最新推荐文章于 2021-04-30 09:08:14 发布