我試圖讓一個類,使訪問Adobe Facebook圖形API更容易沒有所有nitty堅韌的東西進去。這就是我如何去做:我有一個FbNewLib.as和Test.as以及主要的test.fla。無法啓動Facebook.init
在FbNewLib.as中,我有init行來初始化Facebook api。
package
{
import com.facebook.graph.Facebook;
import com.facebook.graph.data.FacebookSession;
import flash.external.ExternalInterface;
public class FbNewLib
{
protected static const app_id:String = "155006914551234" //replace with App Id;
public var scope:String;
public var userId:String;
public var testString:String;
var session:FacebookSession;
public function FbNewLib()
{
trace("FbNewLib initiated.")
}
public function initFacebookLib(scopeString:String):void
{
scope = scopeString;
testString = "testString";
Facebook.init(app_id, onInit);
}
protected function onInit(result:Object, fail:Object):void
{
trace("onInit");
testString = "testStringONINIT";
if (result)
{ //already logged in because of existing session
trace ("On init, already logged in.");
testString = "testStringSUCCESSFUL";
session = Facebook.getSession();
userId = session.uid;
}
else
{
trace("On init, not logged in.");
testString = "testStringUNSUCCESSFUL";
}
}
在我Test.as:
public function Test()
{
trace("connected to test.fla");
init_btn.addEventListener(MouseEvent.CLICK, initFbLib);
}
private function initFbLib(e:MouseEvent):void
{
gotoAndStop(2);
var fb:FbNewLib = new FbNewLib();
fb.initFacebookLib("read_stream");
textBox_txt.text = fb.scope + " " + fb.userId + " " + fb.testString;
}
然而,當我在testApp在Facebook上測試它在我的testApp的Facebook.init()不起作用。 textbox_txt中的內容只是「read_stream,null,testString」
任何人都可以幫忙嗎?這甚至有可能嗎?謝謝!