2013-07-25 35 views
0

我想從PHP傳遞一些變量閃爍,使用此ActionScript代碼IM:回聲不返回PHP的動作連接變量值

public function gameOver(score:Number) 
{ 
    totalScore.text = score.toString(); 

    var scriptVars:URLVariables = new URLVariables(); 
    scriptVars.score = score; 

    var scriptLoader:URLLoader = new URLLoader(); 

    var scriptRequest:URLRequest = new URLRequest("checkScores.php"); 
    scriptRequest.method = URLRequestMethod.POST; 
    scriptRequest.data = scriptVars; 

    scriptLoader.load(scriptRequest); 
    scriptLoader.addEventListener(Event.COMPLETE, handleLoadSuccessful); 
    scriptLoader.addEventListener(IOErrorEvent.IO_ERROR, handleLoadError); 
} 

function handleLoadSuccessful(e:Event):void 
{ 
    trace("Scores Loaded"); 
    var vars:URLVariables = new URLVariables(e.target.data); 
    nickname1.text = vars.nickname; 
    score1.text = vars.score; 
} 

function handleLoadError($evt:IOErrorEvent):void 
{ 
    trace("Load failed."); 
    nickname1.text ="error"; 
} 

這PHP代碼:

<?php 
    ... some code for the mysql connection and select sentence ... 

     $topScores = mysqli_query($con, $topScores); 
     $topScores = mysqli_fetch_array($topScores); 
     echo "&nickname=$topScores[nickname]&score=$topScores[score]"; 

?> 

兩個運行沒有錯誤,問題是,我得到的閃存不是變量值,但變量的名稱,換句話說,我得到的vars.nickname是

$topScores[nickname] 

和vars.score

$topScores[score] 

如果我單獨運行PHP時得到這樣的:

&nickname=jonny&score=100 

這是我想要得到實際的變量值,任何幫助將不勝讚賞。

回答

0

我想你可能只是將flash文件加載到php文件中。您可以更改以下行:

new URLRequest("checkScores.php"); 

喜歡的東西:

new URLRequest("http://localhost/checkScores.php"); 

或者你在你的時候,你在你的問題說:「運行」它在瀏覽器地址欄中看到。

+0

它的工作!但是我收到了一個新錯誤,錯誤#2101:傳遞給URLVariables.decode()的字符串必須是包含名稱/值對的URL編碼查詢字符串。我修正了改變我的php echo sintax來回顯「nickname =」。urlencode($ topScores ['nickname'])。「&score =」。$ topScores ['score'];非常感謝! – FruitDealer