View Full Version : help
vwoohu
07-17-2003, 02:09 PM
I have trouble with the following code (I don't know how to describe it) :
Code:
function getData_result (result) {
_root.tempData = result ;
}
function load () {
trace (_root.tempData) ;
}
function init () {
myService.getData () ;
load () ;
}
init () ;
stop();
I'm trying to process the _root.tempData which is a reference to the result returned from service call GetData. tempData is assigned the result value from the service call but I can't access the tempData in the load function. But I can access it if the init function finish executing. Is there a way to access that variable from the same function call?
Vincent
freddycodes
07-17-2003, 02:39 PM
You can't access until its populated. Which means after the result handler fires. This would fix it.
function getData_result (result) {
_root.tempData = result ;
load () ;
}
function load () {
trace (_root.tempData) ;
}
function init () {
myService.getData () ;
}
init () ;
stop();
vwoohu
07-17-2003, 02:42 PM
I see. but I may not want to use load () in the getData_result function every time. Just inside of the init function. Would a setInterval work?
V
freddycodes
07-17-2003, 02:45 PM
I am not going to try and figure out why you don't want to use load() in the result handler. But a watch would work.
function getData_result (result) {
_root.tempData = result ;
}
load = function (prop, oldVal, newVal) {
trace (newVal);
};
function init () {
_root.watch("tempData", load);
myService.getData () ;
}
init () ;
stop();
vwoohu
07-17-2003, 02:54 PM
nope didn't work :(. is there another function I can use?
V
vwoohu
07-17-2003, 02:57 PM
I can access the tempData after init function has been called. but not inside the same function
freddycodes
07-17-2003, 02:57 PM
I mean it does work, I don't just spew non-working code here for the fun of it, could you post your attempt? Even better to show you it works.
function getData_result (result) {
_root.tempData = result ;
}
load = function (prop, oldVal, newVal) {
trace (newVal);
};
function init () {
_root.watch("tempData", load);
getData_result ("Hello") ;
}
init () ;
stop();
freddycodes
07-17-2003, 03:00 PM
Originally posted by vwoohu
I can access the tempData after init function has been called. but not inside the same function
Like I said before you can't access it until its populated, flash is not going to wait for the result handler to fire before moving to the next line of actionscript. So by trying to access tempData on the line below the service call, just is not going to work.
vwoohu
07-17-2003, 03:31 PM
I apologize; I didn't read your code thoroughly. The code I placed above is a simplified version of the code below. The code involves two service calls, a getUTCID to populate a combobox, and loadData which loads saved data from a database and replaces the top item of combobox with the load item. That's the reason for running both functions inside of Init.
function init () {
service.getUTCID () ; //populates a combo box with data
_root.watch ("_root.utcidlist", service2.loadData (username,unit)) ;
}
function loadData_result (result) {
populate (holder, result,_root.utcidlist) //holder contains the combobox
//push the loaded item to the top of combobox
}
function getUTCID_result () {
.... some code
_root.utcidlist = result ;
}
init() ;
stop();
I know it's not pretty. I hope you can help. Thanks
freddycodes
07-17-2003, 03:39 PM
Would you not be able to use
function init () {
service.getUTCID () ; //populates a combo box with data
}
function loadData_result (result) {
populate (holder, result,_root.utcidlist) //holder contains the combobox
//push the loaded item to the top of combobox
}
function getUTCID_result () {
// .... some code
_root.utcidlist = result ;
service.loadData (username,unit);
}
init() ;
stop();
vwoohu
07-17-2003, 03:44 PM
Thanks that works. I don't know where my head is today.
V
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.