原理是把以下的註解格式存成 php 檔,放置 nbproject 目錄內
/**
* @property CI_Loader $load
* @property CI_Form_validation $form_validation
* @property CI_Input $input
* @property CI_Email $email
* @property CI_DB_active_record $db
* @property CI_DB_forge $dbforge
*/
/**
* @property CI_Loader $load
* @property CI_Form_validation $form_validation
* @property CI_Input $input
* @property CI_Email $email
* @property CI_DB_active_record $db
* @property CI_DB_forge $dbforge
*/
var jf = new JsonFormatter(JSON.stringify(response)); jQuery("#show1").html("<pre>" + jf.getResult() + "</pre>");
import lin.shinder.utils.JsonFormatter; input_txt.text='[{"name":"shinder", "num":"123"}, {"name":"dephne", "num":"124"}]'; format_btn.addEventListener(MouseEvent.CLICK, formatClick); function formatClick(event) { var jf:JsonFormatter=new JsonFormatter(input_txt.text); output_txt.text = jf.result; }
var flashvars = {}; // ← 找到這一行,增加下面的程式碼
// *** START 增加的部份 ***
var strHref = window.location.href;
if ( strHref.indexOf("?") > -1 ) {
var strQueryString = strHref.substr(strHref.indexOf("?")+1);
var aQueryString = strQueryString.split("&");
for ( var iParam = 0; iParam < aQueryString.length; iParam++ ) {
var aParam = aQueryString[iParam].split("=");
flashvars[aParam[0]] = aParam[1];
}
}
// *** END 增加的部份 ***
<?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" minWidth="840" minHeight="500"
applicationComplete="init()"
viewSourceURL="srcview/index.html">
<!-- *** 注意:這裡是用 applicationComplete,不是用 creationComplete *** -->
<fx:Script>
<![CDATA[
import com.facebook.Facebook;
import com.facebook.commands.friends.GetFriends;
import com.facebook.commands.users.GetInfo;
import com.facebook.data.friends.FriendsCollection;
import com.facebook.data.friends.GetFriendsData;
import com.facebook.data.users.FacebookUser;
import com.facebook.data.users.FacebookUserCollection;
import com.facebook.data.users.GetInfoData;
import com.facebook.events.FacebookEvent;
import com.facebook.net.FacebookCall;
import com.facebook.utils.FacebookSessionUtil;
import mx.controls.Image;
private var session:FacebookSessionUtil
private var facebook:Facebook;
private var fbUser:FacebookUser;
private var dictionary:Dictionary;
private function init():void {
// *** 一開始測試時可以先填入 API Key 和 Application Secret
//session = new FacebookSessionUtil("<API Key>", "<Application Secret>", loaderInfo);
session = new FacebookSessionUtil(loaderInfo.parameters.fb_sig_api_key, null, loaderInfo);
// 取得 Facebook Session,有 Session 才有權使用 Facebook API
facebook = session.facebook;
// 取得 Facebook Session 並連結之後,呼叫 onSessionConnect 方法
session.addEventListener(FacebookEvent.CONNECT, onSessionConnect);
if(loaderInfo.parameters.fb_sig_added == true){
// 有登入時,呼叫核對 Session,OK的話發出 CONNECT 事件
session.verifySession();
} else if(loaderInfo.parameters.fb_sig_added == false){
// 沒登入時
navigateToURL(new URLRequest("http://www.facebook.com/login.php?api_key="+loaderInfo.parameters.fb_sig_api_key),"_top");
} else {
// 沒取得資料時
session.login();
btnLogin.visible = true;
}
}
private function onSessionConnect(event:FacebookEvent):void {
// 呼叫取得朋友資料
var call:FacebookCall = facebook.post( new GetFriends() );
// 取得朋友資料之後,執行 onGetFriendsComplete
call.addEventListener(FacebookEvent.COMPLETE, onGetFriendsComplete);
}
private function onGetFriendsComplete(event:FacebookEvent):void {
// 呼叫時用 GetFriends,取得時用 GetFriendsData
var friendsData:GetFriendsData = event.data as GetFriendsData;
var friends:FacebookUserCollection = friendsData.friends;
// 將朋友的 ID 放入 uids 陣列
var uids:Array = [];
for(var i:int=0; i< friends.length; i++) {
var f:FacebookUser = friends.getItemAt(i) as FacebookUser;
uids.push(f.uid);
}
// GetFriends 只能取得朋友的 uid,必須呼叫 GetInfo 才能取得朋友資料
var call:FacebookCall = facebook.post(
// 設定要取得的資料項
new GetInfo(uids, ["name", "pic_square"])
);
call.addEventListener(FacebookEvent.COMPLETE, onGetFriendsAttr);
}
private function onGetFriendsAttr(event:FacebookEvent):void {
// 呼叫時用 GetInfo,取得時用 GetInfoData
var getInfoData:GetInfoData = event.data as GetInfoData;
var userCollection:FacebookUserCollection = getInfoData.userCollection;
dictionary = new Dictionary();
// 一一取出朋友資料
for(var i:int=0; i<userCollection.length; i++) {
var usr:FacebookUser = userCollection.getItemAt(i) as FacebookUser;
var img:Image = new Image();
// 沒有大頭貼時用預設的圖
if(! usr.pic_square) {
img.source = 'http://static.ak.fbcdn.net/pics/q_silhouette.gif';
} else {
img.source = usr.pic_square;
}
img.toolTip = usr.name;
img.buttonMode = true;
// 使用字典以方便用物件取得字串
dictionary[img] = usr.uid;
img.addEventListener(MouseEvent.CLICK,onImageClick);
tilesPic.addElement( img );
}
}
private function onImageClick(event:MouseEvent):void {
var img:Image = event.currentTarget as Image;
navigateToURL(new URLRequest("http://www.facebook.com/profile.php?id="+dictionary[img]),"_blank");
}
]]>
</fx:Script>
<s:Button x="10" y="10" label="點按登入 Facebook" id="btnLogin"
visible="false" click="session.validateLogin()"/>
<s:Scroller x="30" y="30" width="800" height="450">
<s:TileGroup width="100%" height="100%" clipAndEnableScrolling="true" id="tilesPic">
</s:TileGroup>
</s:Scroller>
</s:Application>