2013-04-18 73 views
0

我想從PHP獲取一些用戶數據到AS3。AS3獲得變數,但無法訪問

當我在AS3執行我的代碼,我得到這個:&levelUser=5&livesUser=5並以其良好,這就是我想要的轉移

但是,當我試圖讓只有一個變量我得到這個錯誤的數據:

ReferenceError: Error #1069: Property livesUser not found on String and there is no default value. 
at petRush_fla::MainTimeline/serverResponse() 
at flash.events::EventDispatcher/dispatchEventFunction() 
at flash.events::EventDispatcher/dispatchEvent() 
at flash.net::URLLoader/onComplete() 

而且我不知道是誰發生這種情況,我離開了我的代碼在這裏:

function conectToServer() { 
    //Conectamos al servidor 
    loadingNum.text = "Connection to server..."; 

    var zahtjev:URLRequest=new URLRequest("getUserInfo.php"); 
    var loader:URLLoader = new URLLoader(); 
    loader.addEventListener(Event.COMPLETE, serverResponse); 
    loader.load(zahtjev); 

} 

var livesVar:String; 

function serverResponse(e:Event):void { 
    trace(e.target.data.livesUser); 
    gotoAndStop(2); 
} 

回答

3

返回的數據是一個字符串,你需要創建一個實例的URLVariables像THI S:

function serverResponse(e:Event):void { 
    var myVariables:URLVariables = new URLVariables(e.target.data); 
    trace(myVariables.livesUser); 
    gotoAndStop(2); 
} 

而且我要指出,你的字符串不應該與&開始,它應該是:

levelUser=5&livesUser=5