0
我在Flash這個功能:布爾是Flash真實的,但假在Javascript
public function checkFile(file:String):Boolean{
var b:Boolean;
var responder:Responder = new Responder(function(reply:Boolean):void{
b=reply;
msg("vid_"+file+".flv "+ "exists? " + reply);
setState("ready");
status = "ready";
},
function(res:Object):void{
trace("checkFile call failed");
});
mync.call("checkFile",responder,"vid_"+file);
return b;
}
我可以證實,reply
變量是真實的,但return b
結束了假:
這是JavaScript的我用來調用Flash功能:
function checkFile(){
alert(thisMovie("vidRecorder").checkFile(currentVid));
}
這開闢了一個消息框,說false
,而Flash文件顯示true
發生了什麼事?我該如何修復它,以便我的函數返回與reply
相同的值?
發生什麼事是**異步操作** – Pointy
@Pointy哦不!這聽起來不祥,特別是因爲你把它放在粗體中。讓我看看。 – Houseman
異步和回調的概念在[this thread]中得到了很好的解釋(http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call)。 –