簡體   English   中英

加載程序事件函數內部的AS3調用函數

[英]AS3 call function inside loader event function

我在另一個函數的條件內調用函數時遇到問題。 我已經嘗試過了,並且效果很好,但這取決於調用的位置。

過程:我有checkCode(); 完成並發送表單時調用的函數。

private function checkCode():void {
    var url = "checktrue.php";
    var loader:URLLoader = new URLLoader;
    var urlreq:URLRequest = new URLRequest(url);
    var urlvars:URLVariables = new URLVariables;
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    urlreq.method = URLRequestMethod.POST;
    urlvars.codeVar = formattedCode;
    urlreq.data = urlvars;
    loader.addEventListener(Event.COMPLETE, completed); //Completed function
    status.text = "calling loader";
    loader.load(urlreq);
}

當php完成時,將調用“ completed”並:

private function completed(event:Event = null):void {
    var loader2: URLLoader = URLLoader(event.target);
    var checked:String = loader2.data.checked;
    var codetrue:String = loader2.data.codetrue;

    if(checked == "1" || codetrue == null || codetrue == "") {
        trace("WRONG");
    }
    else{
        download(); //download function
        trace("ok");
    }
}

在這里,我得到了php var,並檢查它們是否有效以調用download()函數。

public function download():void {
    req = new URLRequest(proxy + filename);
    file = new FileReference();

    file.addEventListener(Event.COMPLETE, completeHandler);
    file.addEventListener(Event.CANCEL, cancelHandler);
    file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
    file.download(req, "file.zip");

}

是否有可能無法從“完成的”加載程序函數調用此函數? 非常感謝你!

您需要將下載功能放在另一個按鈕中才能正確使用。 或創建您自己的事件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM