如何在外部类中实现 RemoteObject?
代码如下:
public class Schem
{
public var info:String="";
public function Schem()
{
}
public function loadCurrentSchem():void
{
var ro:RemoteObject = new RemoteObject("Hibernatetest");
ro.endpoint = "http://Jesus/blazeds/messagebroker/amf";
ro.addEventListener(ResultEvent.RESULT,onResult);
ro.getCells();
info = info + "Loader called ... \n";
}
public function onResult(event:ResultEvent):void
{
var array:ArrayCollection = event.result as ArrayCollection;
info = info + "Schemlength = " + String(array.length)+ "\n";
}
private function onFault(event:FaultEvent):void
{
info = info + "Errorhandler Called";
}
//Eventhandlers
//Getters, Setters
}
不幸的是,当我调用 loadCurrentSchem() 函数时,它没有到达 eventHandler。怎么了?
我就是这样称呼这个班级的:
<fx:Script>
<![CDATA[
import argoseye.main.Golem;
import argoseye.main.Schem;
import mx.collections.ArrayCollection;
import mx.rpc.AsyncToken;
import mx.rpc.Responder;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;
protected function button1_clickHandler(event:MouseEvent):void
{
var schem:Schem = new Schem();
schem.loadCurrentSchem();
textfeld.text = schem.info;
}
]]>
</fx:Script>
那里。
Heres the code:
public class Schem
{
public var info:String="";
public function Schem()
{
}
public function loadCurrentSchem():void
{
var ro:RemoteObject = new RemoteObject("Hibernatetest");
ro.endpoint = "http://Jesus/blazeds/messagebroker/amf";
ro.addEventListener(ResultEvent.RESULT,onResult);
ro.getCells();
info = info + "Loader called ... \n";
}
public function onResult(event:ResultEvent):void
{
var array:ArrayCollection = event.result as ArrayCollection;
info = info + "Schemlength = " + String(array.length)+ "\n";
}
private function onFault(event:FaultEvent):void
{
info = info + "Errorhandler Called";
}
//Eventhandlers
//Getters, Setters
}
Unfortunatly, its doesnt reach the eventHandler, when i call the loadCurrentSchem() function. Whats wrong?
This is how i call the class:
<fx:Script>
<![CDATA[
import argoseye.main.Golem;
import argoseye.main.Schem;
import mx.collections.ArrayCollection;
import mx.rpc.AsyncToken;
import mx.rpc.Responder;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;
protected function button1_clickHandler(event:MouseEvent):void
{
var schem:Schem = new Schem();
schem.loadCurrentSchem();
textfeld.text = schem.info;
}
]]>
</fx:Script>
There.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您没有正确确保正确调用结果处理程序。问题是,当您使用:时,
您已将:的值设置
为文本字段的文本,并且该值在结果处理程序中不会更改。
您至少可以通过两种方式解决此问题:
EventDispatcher
扩展您的Schem
类,并将事件元数据放置在其中。类:
然后在您的 MXML 类中:
Schem
类:在 MXML 中:
希望这有帮助! :)
The problem is you haven't proper made sure the result handler called correctly. The thing is that when you use:
you've set the value of:
as a text of the text field and this value isn't changed in a result handler.
You can resolve this issue at least two ways:
Schem
class fromEventDispatcher
and place events metadata there.The class:
Then in your MXML class:
Schem
class:And in MXML:
Hope this helps! :)