
Build a distributed application with the ActionScript object adapter 225
Verify that your code is correct
Your code should match the following code example. Verify that the content is correct and
save the lesson1.mxml file.
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
height="100%" width="100%"
creationComplete="initApp();">
<mx:Script>
<![CDATA[
import mx.data.DataService;
import mx.data.events.*;
import mx.rpc.AsyncToken;
import mx.rpc.events.*;
import mx.messaging.events.*;
import mx.utils.ObjectProxy;
public var noteObj:Object = new Object();
public var getToken:AsyncToken;
private var ds:DataService;
[Bindable]
public var noteProxy:ObjectProxy;
public function initApp():void {
ds = new DataService("notes");
ds.addEventListener(ResultEvent.RESULT, resultHandler);
ds.autoCommit = false;
noteObj.noteId = 1;
noteObj.noteText =
"Type your notes here and share them with other clients!";
getToken = ds.getItem(noteObj, noteObj);
}
public function resultHandler(event:ResultEvent):void {
if (event.token == getToken)
noteProxy = ObjectProxy(event.result);
}
]]>
</mx:Script>
<mx:Binding source="log.text" destination="noteProxy.noteText"/>
<mx:TextArea id="log" width="100%" height="80%"
text="{noteProxy.noteText}"/>
<mx:Button label="Send" click="ds.commit();"/>
</mx:Application>
Commenti su questo manuale