HTTPService 事件侦听器,以便在“.send”发送时触发某些内容。方法从 XML 获取数据
大家好。
我在使用 Flex 和 XML 文件中的远程数据方面进行了一些“培训”。
这是我的 HTTPService
<mx:HTTPService id="loginData" url="com-handler/basic.xml" showBusyCursor="true">
</mx:HTTPService>
,我有一个按钮,当单击它时,它会调用一个函数,该函数调用 loginData.send
并执行一些 IF 条件,该 IF 条件依赖于 loginData< 返回的数据/代码>。
该条件不起作用,因为它是在 loginData.send
旁边调用的,并且 .send 方法仍然没有从 XML 文件返回值。但是,如果您在第一次单击后每秒单击第二次,则 IF 条件起作用。
因此,为了处理这个问题,我想做一个 eventListener,以便当 loginData.send
从 XML 返回数据时,它会触发 IF 条件。但我不知道该怎么做。
你能帮助我吗?
Good day everybody.
I've doing a bit of "training" at working with Flex and Remote Data from XML files.
This is my HTTPService
<mx:HTTPService id="loginData" url="com-handler/basic.xml" showBusyCursor="true">
</mx:HTTPService>
I have a button and when its clicked its call a function, that calls loginData.send
and does a little IF condition, that IF condition relies on the data returned by loginData
.
The condition doesn't work because its called right next to the loginData.send
, and .send method still didn't returned the values from the XML file. But if you click it a second time a second after the first click the IF condition works.
So to deal with i wanted to do a eventListener so that when loginData.send
returned the data from the XML it fires up the IF condition. But i don't know how to do it.
Can you help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HTTPService 的 send 方法返回一个 AsyncToken,您可以向其中添加响应程序以及任意数据。因此,在 Button 的单击处理程序中:
此外,MXML 可以声明一个结果处理程序:
AsyncToken 的一个有趣的方面是它是一个动态对象,这意味着您可以对其应用任意属性:
现在,在 myResultFunction 中您可以访问 < em>event.token.myArbitraryProperty 用于条件或任何您可能需要的内容。
The send method of HTTPService returns an AsyncToken, to which you can add a Responder, as well as arbitrary data. So in the click handler of your Button:
Additionally, the MXML can declare a result handler:
One interesting aspect of AsyncToken is that it is a dynamic object, meaning you ca apply arbitrary properties to it:
Now, in the myResultFunction you can access event.token.myArbitraryProperty for use in conditionals or whatever you may need.