如何从 PHP 检索变量到 Flex
好的 - 对于 99% 的人来说这是一个简单的答案。我有一个自定义类“Users()”。在 PHP 中,我已正确填充所有值。当我进入 Flash Builder - 并执行测试功能时 - 所有数据都会正确返回。但是,当我单击按钮并引用 CallResponder 的 lastResult 属性时,它第一次出现 NULL,然后如果第二次单击该按钮,它将返回正确的结果。我缺少哪一步?昨晚我也遇到了类似的问题,并且感到非常沮丧 - 特别是因为我知道这是我忽略的一些小细节。
为了澄清起见 - 假设有一个名为 button1 的按钮,
那么,button1 的点击处理程序: 1) 验证文本输入属性 2) 询问服务器该用户和密码是否匹配 3)如果他们这样做 - 那么我希望它获取所有特定用户信息并将其放入用户类中。再次 - 当我在 Flash Builder 中测试此函数/方法时,所有值都会按预期返回。只需单击第一个按钮,它们就会返回 NULL...第二次单击它们会填充得很好 - IE-
Alert.show(currentUser.userFirstName); (第一次点击 - NULL) Alert.show(currentUser.userFirstName); (第二次点击 - “杰克”)
非常感谢任何帮助!我为此自责,我知道我错过了一些简单、简单的步骤。
感谢所有提前抽出时间提供帮助的人!
-CS
Okay - an easy answer for 99% of you. I have a custom class 'Users()'. In PHP I have all the values being populated correctly. When I go to Flash Builder - and do the test function - All the data comes back properly. However, when I click a button and refer to the lastResult property of the CallResponder - it comes up NULL the first time, and then if the button is clicked a second time it will return the correct result. What step am I missing? I had the same problem with something simliar last night and am getting BEYOND frustrated - especially since I know it is some SMALL detail I'm overlooking.
So just for clarification - lets say there is a button named button1
So button1's click handler:
1) Validates the text input properties
2) Asks the server if that user and password match
3) If they do - then I want it to grab all of that specific users info and put it into a User class. Again - when I test this function/method from within Flash Builder all the values come back as they should. It's just on the first button click they come back NULL...he second click they populate fine - I.E.-
Alert.show(currentUser.userFirstName); (First Click - NULL)
Alert.show(currentUser.userFirstName); (Second click - "Jack")
Any help is much appreciated!!! I am beating myself up over this and I know it is some simple, simple step I'm missing.
Thank you to all who take the time to help in advance!
-CS
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简单地回答这个问题,Flex 是异步的...这意味着您在下一行中执行的代码可能会在 PHP 代码完成之前发生。当您第一次单击该按钮时,尚未填充最后的结果。单击按钮会立即发生,但数据需要几秒钟才能返回。同样,第二次单击该按钮时,您将获得最后用户信息,而不是当前用户!
您需要做的就是等待数据返回后再进行任何操作。为此,请向您的服务添加事件侦听器。它称为“结果”处理程序。这方面有很多很好的例子。
在处理程序中,继续使用 lastResult... 或仅使用
event.result
来提醒弹出窗口。应该有你要找的东西。To answer this simply, Flex is asynchronous... meaning the code you've executed in the next line may happen before your PHP code is done. The last result isn't populated yet when you've clicked the button the first time. The button clicking happens INSTANTLY, but the data needs a few seconds to come back. Likewise, the second time you click the button, you're going to get the last users info, not the current ones!!!
What you need to do is wait for the data to come back before you do anything. To do this, add an event listener to your service. It's called a "result" handler. There's a lot of good examples of this.
In the handler, go ahead and alert your popup with lastResult... or just,
event.result
. Should have what you're looking for.