php - AS2 Wait to Return -
i'm working on as2 project. have function links php packets. basically, packet sent, sends information based on argument. simple, really.
the issue original function needs return data. need wait packet come in order return. except cannot attach "return" function listener.
function handlereturnnicknamebyid(id) { nfunctioncomplete = 0; trace("api : handlegetswidbyid"); airtower.send(airtower.play_ext, "friends#getplayerinfobyid", [id], "str", shell.getcurrentserverroomid()); airtower.addlistener('getplayerinfobyid', handlereturnnickname); while(nfunctioncomplete < 700) { if(nickready == true) { nfunctioncomplete = 701; return(nicktoreturn); } nfunctioncomplete++; } } function handlereturnnickname(obj) { airtower.removelistener('getplayerinfobyid', handlereturnnickname); obj.shift(); nicktoreturn = obj[1]; nickready = true; }
this idea had getting work. understand horribly ineffective, why i'm asking here.
ultimately question is: in as2, can make function "wait" before return?
to looking for, can use callback function called when data loaded. code :
function handlereturnnicknamebyid(id:number, callback:function): void { airtower.send(airtower.play_ext, "friends#getplayerinfobyid", [id], "str", shell.getcurrentserverroomid()); airtower.addlistener('getplayerinfobyid', handlereturnnickname); function handlereturnnickname(obj): void { airtower.removelistener('getplayerinfobyid', handlereturnnickname); obj.shift(); var nicktoreturn = obj[1]; // run callback function , pass needed data callback(nicktoreturn); } } // function called when data loaded function my_callback(data): void { // here can use data trace('loaded data : ' + data); }
and execute :
handlereturnnicknamebyid(id, my_callback);
hope can help.
Comments
Post a Comment