我试图让一个类,使访问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”
任何人都可以帮忙吗?这甚至有可能吗?谢谢!