而因為吐出來的格式是json..所以稍微研究了一下
下面是我做出的筆記
1. 請去抓js3corelib,我們需要用到裡面的json library
2. 使用
JSON.decode()
,它會把json object轉換成as3的object..下面是一個sample code
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:mycomp="*">
<fx:Script>
<![CDATA[
import com.adobe.serialization.json.*;
import flash.net.*;
protected function onClick(event:MouseEvent):void
{
var path:String = "http://your_url/";
var ur:URLRequest = new URLRequest(path);
var ul:URLLoader = new URLLoader();
ul.load(ur);
ul.addEventListener(Event.COMPLETE, onComplete);
}
protected function onComplete(evt:Event): void {
var ul:URLLoader = evt.target as URLLoader;
var obj:Object = JSON.decode(ul.data);
lbl.text = obj.foo;
}
]]>
</fx:Script>
<mx:HBox>
<s:Button label="Get" click="onClick(event)"/>
<s:Label id="lbl"/>
</mx:HBox>
</s:Application>
沒有留言:
張貼留言