2011-03-08 55 views
1

嗨,我是新來flex, 我想用flex曲線圖來顯示存儲在mysql表中的數據。任何人都可以建議我如何做到這一點與Flex作爲用戶界面和MySQL作爲數據庫,我不知道如何調用.php文件在flex從MySQL查詢。我想顯示一些數據的時間v/s溫度連接到MySQL使用PHP中的flex

我寫了一個php文件來查詢數據從mysql,但我的flex程序無法連接到mysql,有沒有我需要更新的任何配置。我正在使用XAMPP

+0

你知道HTTPService嗎? http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/rpc/http/mxml/HTTPService.html您還可以配置您的後端:右鍵單擊項目 - >屬性 - > Flex服務器,但我尚未與此屬性一起工作。 – hering 2011-03-08 15:32:24

回答

1

一般來說,沒有額外的配置需要使其工作,因爲她在評論中表示,HTTPService將滿足您的需求。這裏有您需要做什麼:

private var myCollection:ArrayCollection; 

public function creationComplete(event:Event):void 
{ 
    var myService:HTTPService = new HTTPService(); 
    myService.url = "myscript.php" 
    myService.method = "POST"; 
    myService.addEventListener(ResultEvent.RESULT, resultHandler); 
    myService.send(); 
} 

public function resultHandler(event:ResultEvent):void 
{ 
    if(event.result..entries is ArrayCollection) 
     myCollection = event.result..entries; 
    else if(event.result..entries is Object) 
     myCollection = new ArrayCollection(event.result..entries) 
} 

我假設你添加監聽到該服務呼叫住在創造完整的調用創建功能齊全任何控制。我還假設你有(php生成)xml結構,如:

<entry> 
    <entries>1</entries> 
    <entries>2</entries> 
</entry> 
+0

要注意,如果您看不到任何內容,請將偵聽器添加到FaultEvent.FAULT字符串的HTTPService,如果您從服務器獲得除了正常消息之外的其他信息,您將收到消息。 – shaunhusain 2011-03-08 16:15:09