基于flex4技术从零开发flex博客系统 : 4 数据存储
2009-05-05 12:06:22 来源:WEB开发网pm.makePersistent用于存储Greeting实例对象。使用之后记得要记得调用pm.close。该接口需要两个参数,一为用户名称,一为greeting内容。如果存储成功,将返回true。
三,客户端代码调用
好了,server端已经准备就绪,现在客户端可以调用了。修改Index.mxml,修改greetViaRemoting方法,代码如下:
<FxApplication xmlns="http://ns.adobe.com/mxml/2009" initialize="configRemoting()">
<Script>
<![CDATA[
import mx.controls.Alert;
import flash.net.URLLoader;
import flash.net.URLRequest;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.AbstractOperation;
import mx.rpc.remoting.RemoteObject;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.collections.ArrayCollection;
import mx.managers.CursorManager;
[Bindable]
private var _greetingData : ArrayCollection;
private var _remotingObj : RemoteObject = new RemoteObject("GenericDestination");
private function configRemoting() : void
{
_remotingObj.source = "sban.flexblog.HelloWorld";
_remotingObj.endpoint = "weborb.wo";
}
private function greetViaRemoting() : void
{
var op : AbstractOperation = _remotingObj.getOperation("greet2");
op.addEventListener(ResultEvent.RESULT,
function(event : ResultEvent) : void
{
Alert.show( event.result.toString() );
};
);
op.send(vNameTxt.text,vContentTxt.text);
}
]]>
</Script>
<layout>
<BasicLayout />
</layout>
<VGroup width="100%">
<HGroup>
<Label text="user:" />
<FxTextInput id="vNameTxt" text="sban" />
</HGroup>
<HGroup>
<Label text="content:" />
<FxTextInput id="vContentTxt" text="greeting content" />
</HGroup>
<HGroup>
<FxButton id="vSendBtn" label="remoting greet"click="greetViaRemoting()" />
</HGroup>
</VGroup>
<TextBox text="by sban" color="gray" bottom="10" right="10" />
</FxApplication>
更多精彩
赞助商链接