SWF 为 null Facebook Graph API 和 Actionscript 3 库
使用 Facebook Adobe Actionscript 3 1.5 Graph API 调用 Facebook.login(handleLogin, {perms:"user_photos,publish_stream"}) 时,我在 Firebug 控制台中收到“swf is null”。不确定问题是什么,但这是 AS3 代码:
package alvincrespo
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.external.ExternalInterface;
import flash.text.TextField;
import fl.controls.Button;
import flash.utils.Timer;
import flash.events.TimerEvent;
//-----------------------
//Facebook Classes
import com.facebook.graph.Facebook;
import com.facebook.graph.data.FacebookSession;
import com.facebook.graph.net.FacebookRequest;
//-----------------------
public class Main extends MovieClip
{
public var btn_login :Button;
public var txt_status :TextField;
private var APP_ID :String = ""; //put in the app id here
public function Main():void
{
trace("Main");
btn_login.addEventListener(MouseEvent.CLICK, handleLoginClick);
Facebook.init(APP_ID, handleInit);
}
private function handleInit(response:Object, fail:Object):void
{
trace("Main :: handleInit");
if(response)
{
changeToLoginState();
}
else
{
trace("Main :: handleInit : Did not Init!")
}
}
private function handleLogin(response:Object, fail:Object):void
{
trace("Main :: handleLogin");
if(response)
{
changeToLoginState();
}
else
{
trace("Main :: handleLogin : Did not Log In!")
}
}
private function handleLogout(success:Boolean):void
{
trace("Main :: handleLogout");
btn_login.label = 'Login';
txt_status.text = "Logged Out";
}
private function handleLoginClick(evt:MouseEvent):void
{
trace("Main :: handleLoginClick");
if(Facebook.getSession() == null || Facebook.getSession().accessToken == null)
{
trace("Main :: handleLoginClick : if");
var fbLoginTimer:Timer = new Timer(1000, 1);
fbLoginTimer.addEventListener(TimerEvent.TIMER_COMPLETE, doFBLoginTimerComplete);
fbLoginTimer.start();
}
else
{
trace("Main :: handleLoginClick : else");
Facebook.logout(handleLogout);
}
}
private function changeToLoginState():void
{
trace("Main :: changeToLoginState");
btn_login.label = 'Logout';
txt_status.text = "Logged In";
}
private function handleSessionChanged(success:Object, fail:Object):void
{
trace("Main :: handleSessionChanged");
changeToLoginState();
}
private function doFBLoginTimerComplete(evt:TimerEvent):void
{
trace("Main :: doFBLoginTimerComplete");
evt.target.stop();
Facebook.login(handleLogin, {perms:"user_photos, publish_stream"});
/*Facebook.callJS('redirect', {perms:"user_photos, publish_stream"});*/
}
}
}
这是 HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Page Title</title>
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
</head>
<body>
<div id="FlashDiv">
<h1>You need at least Flash Player 9.0 to view this page.</h1>
<p>
<a href="http://www.adobe.com/go/getflashplayer">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
</p>
</div>
<script type="text/javascript">
function redirect()
{
alert("redirect");
var params = window.location.toString().slice(window.location.toString().indexOf('?'));
top.location = 'https://graph.facebook.com/oauth/authorize?client_id=&scope=email,publish_stream,offline_access,read_stream&redirect_uri=http://apps.facebook.com/someapp' + params;
}
$(document).ready(function(){
swfobject.embedSWF("main.swf", "FlashDiv", "550", "400", "10");
});
</script>
</body>
</html>
真的不确定问题是什么。任何帮助,都会很棒!谢谢!
I am getting a 'swf is null' in the Firebug console when calling Facebook.login(handleLogin, {perms:"user_photos, publish_stream"}) using the Facebook Adobe Actionscript 3 1.5 Graph API. Not sure what the issue is, but here is the AS3 Code:
package alvincrespo
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.external.ExternalInterface;
import flash.text.TextField;
import fl.controls.Button;
import flash.utils.Timer;
import flash.events.TimerEvent;
//-----------------------
//Facebook Classes
import com.facebook.graph.Facebook;
import com.facebook.graph.data.FacebookSession;
import com.facebook.graph.net.FacebookRequest;
//-----------------------
public class Main extends MovieClip
{
public var btn_login :Button;
public var txt_status :TextField;
private var APP_ID :String = ""; //put in the app id here
public function Main():void
{
trace("Main");
btn_login.addEventListener(MouseEvent.CLICK, handleLoginClick);
Facebook.init(APP_ID, handleInit);
}
private function handleInit(response:Object, fail:Object):void
{
trace("Main :: handleInit");
if(response)
{
changeToLoginState();
}
else
{
trace("Main :: handleInit : Did not Init!")
}
}
private function handleLogin(response:Object, fail:Object):void
{
trace("Main :: handleLogin");
if(response)
{
changeToLoginState();
}
else
{
trace("Main :: handleLogin : Did not Log In!")
}
}
private function handleLogout(success:Boolean):void
{
trace("Main :: handleLogout");
btn_login.label = 'Login';
txt_status.text = "Logged Out";
}
private function handleLoginClick(evt:MouseEvent):void
{
trace("Main :: handleLoginClick");
if(Facebook.getSession() == null || Facebook.getSession().accessToken == null)
{
trace("Main :: handleLoginClick : if");
var fbLoginTimer:Timer = new Timer(1000, 1);
fbLoginTimer.addEventListener(TimerEvent.TIMER_COMPLETE, doFBLoginTimerComplete);
fbLoginTimer.start();
}
else
{
trace("Main :: handleLoginClick : else");
Facebook.logout(handleLogout);
}
}
private function changeToLoginState():void
{
trace("Main :: changeToLoginState");
btn_login.label = 'Logout';
txt_status.text = "Logged In";
}
private function handleSessionChanged(success:Object, fail:Object):void
{
trace("Main :: handleSessionChanged");
changeToLoginState();
}
private function doFBLoginTimerComplete(evt:TimerEvent):void
{
trace("Main :: doFBLoginTimerComplete");
evt.target.stop();
Facebook.login(handleLogin, {perms:"user_photos, publish_stream"});
/*Facebook.callJS('redirect', {perms:"user_photos, publish_stream"});*/
}
}
}
And here is the HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Page Title</title>
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
</head>
<body>
<div id="FlashDiv">
<h1>You need at least Flash Player 9.0 to view this page.</h1>
<p>
<a href="http://www.adobe.com/go/getflashplayer">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
</p>
</div>
<script type="text/javascript">
function redirect()
{
alert("redirect");
var params = window.location.toString().slice(window.location.toString().indexOf('?'));
top.location = 'https://graph.facebook.com/oauth/authorize?client_id=&scope=email,publish_stream,offline_access,read_stream&redirect_uri=http://apps.facebook.com/someapp' + params;
}
$(document).ready(function(){
swfobject.embedSWF("main.swf", "FlashDiv", "550", "400", "10");
});
</script>
</body>
</html>
Really not sure what the issue is. Any help, would be great! Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,您需要设置对象标记的名称和 ID,您可以使用 SWFObject 轻松完成此操作,如下所示。您还需要设置适当的allowscriptaccess 属性。
Basically, you need to set the name and ID of the object tag, you can do that easily with SWFObject as you can see below. You also need to have the appropriate allowscriptaccess attribute set.