box-o-sand/PracticingFlex/03a6-shared-objects/SharedObjectExample.mxml

53 lines
1.8 KiB
Plaintext
Raw Normal View History

2010-02-18 20:11:11 +00:00
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="initSharedObject()">
<mx:Script>
<![CDATA[
import flash.net.SharedObject;
public var sharedObj:SharedObject;
private function initSharedObject():void{
sharedObj = SharedObject.getLocal("myTasks");
if (sharedObj.size > 0)
textareaTasks.text=sharedObj.data.tasks;
}
public function localconnectionHandler(msg:String):void {
textareaTasks.text= textareaTasks.text + msg + "\n";
}
private function clearTasks(event:MouseEvent):void {
textareaTasks.text="";
}
private function saveTasks(event:MouseEvent):void {
sharedObj.data.tasks = textareaTasks.text;
sharedObj.flush();
}
private function deleteSavedTasks(event:MouseEvent):void {
sharedObj.clear();
}
]]>
</mx:Script>
<mx:Panel horizontalCenter="0" verticalCenter="0.5" verticalGap="15"
paddingLeft="20" paddingRight="20" paddingBottom="20" paddingTop="20"
height="300">
<mx:Label text="Your tasks are..."/>
<mx:TextArea id="textareaTasks"
top="20" left="20" right="20" bottom="20"
width="100%" height="100%"/>
<mx:HBox>
<mx:Button id="btnClearTasks" click="clearTasks(event)"
label="Clear Tasks"/>
<mx:Button id="btnSaveTasks" click="saveTasks(event)"
label="Save Tasks to Shared Object"/>
<mx:Button id="btnDeleteSavedTasks" click="deleteSavedTasks(event)"
label="Delete Saved Shared Object Tasks"/>
</mx:HBox>
</mx:Panel>
</mx:Application>