ActionScript 3 AS3:Facebook身份验证类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3:Facebook身份验证类相关的知识,希望对你有一定的参考价值。
package com.chrisaiv
{
import com.facebook.events.FacebookEvent;
import com.facebook.utils.FacebookSessionUtil;
import flash.events.Event;
import flash.events.EventDispatcher;
import mx.controls.Alert;
public class FBAuthenticate extends EventDispatcher
{
private var session:FacebookSessionUtil;
private var _currentMethod:Function;
public function FBAuthenticate( fbSession:FacebookSessionUtil, func:Function )
{
_currentMethod = func;
session = fbSession;
session.addEventListener( FacebookEvent.WAITING_FOR_LOGIN, fbWaitingForLoginHandler, false, 0, true );
session.addEventListener( FacebookEvent.CONNECT, fbOnConnectHandler, false, 0, true );
session.login();
}
/**************************************
* Facebook Connect/Login Event Handlers
**************************************/
private function fbOnConnectHandler( e:FacebookEvent ):void
{
//Continue where the user last left off before requiring Authentication
dispatchEvent( new Event( Event.COMPLETE ) );
}
private function fbWaitingForLoginHandler( e:FacebookEvent ):void
{
showAlert( "Click OK after you've logged in", "Logging In" );
}
private function fbValidateLogin( e:Event ):void
{
session.validateLogin();
}
/**************************************
* Alert
**************************************/
private function showAlert( message:String, header:String ):void
{
//The user has returned from the log-in page and are now clicking "OK"
var alert:Alert = Alert.show( message, header );
alert.addEventListener( Event.CLOSE, fbValidateLogin, false, 0, true );
alert.addEventListener( Event.CLOSE, alertCloseHandler, false, 0, true );
}
private function alertCloseHandler( e:Event ):void
{
}
/**************************************
* Getters / Setters
**************************************/
public function get currentMethod():Function
{
return _currentMethod;
}
}
}
/**************************
* This belongs outside of the class
**************************/
private function isAuthenticated():Boolean
{
if( fbSession == null || !fbSession.facebook.is_connected ){
return false;
}
return true;
}
private function fbGoAuthenticate( method:Function ):void
{
fbAuthenticate = new FBAuthenticate( fbSession, method );
fbAuthenticate.addEventListener( Event.COMPLETE, fbAuthenticateComplete, false, 0, true );
}
private function fbAuthenticateComplete( e:Event ):void
{
updateStatus( "You are logged into Facebook" );
var currentMethod:Function = FBAuthenticate(e.currentTarget).currentMethod;
//Continue where the User Last Left Off
currentMethod();
}
private function getPhotoAlbums():void
{
//-- AUTHENTICATE USER: Force USER to Login() Before calling FB API
if( !isAuthenticated() ){ fbGoAuthenticate( arguments.callee ); return; }
var call:FacebookCall = fbook.post( new GetAlbums( fbook.uid ) );
call.addEventListener( FacebookEvent.COMPLETE, photoAlbumsCompleteHandler, false, 0, true );
}
private function photoAlbumsCompleteHandler( e:FacebookEvent ):void
{
var albumsResponseData:GetAlbumsData = e.data as GetAlbumsData;
}
以上是关于ActionScript 3 AS3:Facebook身份验证类的主要内容,如果未能解决你的问题,请参考以下文章
[ActionScript 3.0] AS3.0 水面波纹效果