I have generated a service call to a service called ServiceName.getService() – I can successfully pull data displayed inside mxml layout elements, but, instead of displaying it, I just want to assign it to a global.
I always get an error on the second line below – apparently the value has not been fetched yet. I have also tried adding a listener, and setting the global value on COMPLETE, but that is apparently never called. (I am guessing this generated service call stuff does not actually trigger a COMPLETE?)
Short question is: how do you simply assign a variable after you have loaded it via a service data call. (Not just HTTP)
getServiceResult.token=ServiceName.getService(); GlobalVars.variablename = getServiceResult.lastResult.variablename;
That is correct. In Flex / Flash the remote server calls asynchronous. That means your second line–to set the value–is potentially running before the service call has executed.
You should set up a result handler on the service call. This is most likely the same thing you did when you got things to work for display.
Like this:
And elsewhere in your code:
When you talk about adding a listener on complete, I’m not sure what you refer to. Do you mean creationComplete? or updatecomplete? Or applicationComplete? Or something else altogether.