2011-08-06 36 views
1

我是新來的Flash,它真的讓我煩惱,我無法找到如何做一個簡單的URL請求。我不想做XML。我只需要讀取一個文件,例如example.com/file.txt或example.com/file.php。Flash - 動作腳本2 - HTTP請求

我用ActionScript 2.0搖擺不定,沒有人知道如何在FLASH中做一個簡單的HTTP請求,感謝它讓我瘋狂,我無法找到它。

提前致謝。

回答

1

從.txt文件,比使用這樣的代碼讀取使用PHP代碼:

function loadData():Void { 
var recive:LoadVars = new LoadVars(); 
recive.onLoad = function(loading:Boolean):Void { 
    if (loading) {     //if were variables succesfully loaded 
     trace(unescape(this)); //trace PHP variables 
    } else {         
     trace("Error!"); // if wasn't process succesfull, trace error 
    } 
}; 
var send:LoadVars = new LoadVars();  
send.premenna = "text";   // send to $_POST['text'] in php 
send.sendAndLoad("www.web.comfile.php", recive, "POST"); //send and load variables 
} 
_root.tlacitko.onRelease = loadData; //do it after button is pressed 

總之,使用的LoadVars加載PHP瓦爾。 (不要閱讀註釋....)

0

正如您所提到的,在ActionScript 2.0中通過HTTP檢索數據的方法主要是設計用於使用XML對象獲取XML,或如FrewCen的答案獲取變量 - 值對Load忱。但是,如果你喜歡,以獲得原始數據的保持,可以這麼說HTTP請求的,可以使用Load忱(或XML對象),並定義了一個偵聽器昂達事件:

http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001161.html