How To Retrieve Variable From PHP to Flex
Okay - an easy answer for 99% of you. I have a cus开发者_C百科tom 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
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.
精彩评论