2012-11-27 66 views
1

這是我曾經經歷過的最閃閃發光的事情。 PHP程序員說我的代碼不會傳遞任何變量(變量名稱和電子郵件)。這是as3。 我把PHP但程序設計師告訴我,PHP已經沒有關係了,我沒有解決上傳文件時,該地址是正確的(當我鍵入它)PHP沒有收到來自as3的變量?

texti.visible = false; 

var loader : URLLoader = new URLLoader; 
var urlreq:URLRequest = new URLRequest("https://[someadress]/upload.php"); 
var urlvars:URLVariables = new URLVariables(); 
loader.dataFormat = URLLoaderDataFormat.VARIABLES; 
urlreq.method = URLRequestMethod.POST;  

    //var urlreq:urlreq = new URLRequest("https://localhost/upload/upload.php"); 

    var imageTypes:FileFilter = new FileFilter("Images (*.jpg, *.jpeg, *.png)", "*.jpg; *.jpeg; *.gif; *.png"); 

    var allTypes:Array = new Array(imageTypes); 

    var fileRef:FileReference = new FileReference(); 

    fileRef.addEventListener(Event.SELECT, syncVariables); 
    fileRef.addEventListener(Event.COMPLETE, completeHandler); 
    fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler); 

    btn_browse.addEventListener(MouseEvent.CLICK, browseBox); 
    btn_upload.addEventListener(MouseEvent.CLICK, uploadVars);   

    function browseBox(event:MouseEvent):void { 
     fileRef.browse(allTypes); 
    } 

    function uploadVars(event:MouseEvent):void {    
     urlvars.Name = "somename"; 
     urlvars.Email = "[email protected]"; 
     //urlvars.fb_id = Main.facebook1; 
     urlvars.picname = fileRef.name; 
     trace(urlvars.Name); 
     trace(urlvars.Email); 
     loader.load(urlreq); 
     fileRef.upload(urlreq); 
     btn_upload.visible = true; 
    } 

    function syncVariables(event:Event):void { 
     texti.text = "" + fileRef.name; 
     //blocker.visible = false; 
     btn_upload.visible = true;   
    } 

    function completeHandler(event:Event):void { 
     trace("h1"); 

     var bytestoLoad:Number = loaderInfo.bytesTotal; 
     var numberLoaded:Number = loaderInfo.bytesLoaded; 
     if (bytestoLoad == numberLoaded) 
     { 
     gotoAndStop(2); 

     trace(fileRef.name);     

     t_status.gotoAndPlay(2); 
     btn_upload.removeEventListener(MouseEvent.CLICK, uploadVars); 
     btn_browse.removeEventListener(MouseEvent.CLICK, browseBox); 

     } 
     else 
     {    
      trace("wtf?");    
     } 

    } 

    function progressHandler(event:ProgressEvent):void { 
     trace("inprogress") 
    } 

任何幫助將可以理解的,因爲我已經在幾個小時的代碼現在仍然沒有任何進展

回答

2

你忘了一行代碼改變次要的東西,你所說的負載權之前:

urlreq.data = urlvars; 

您需要分配瓦爾至請求。

+0

之前呼叫負載?如之前 'loader.load(urlreq); '? – Alex

+0

是的,在調用加載之前需要將變量分配給urlreq – Gone3d

+0

Adob​​e Docs:http://help.adobe.com/zh_CN/FlashPlatform/reference/actionscript/3/flash/net/URLVariables.html#includeExamplesSummary – Gone3d