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;
}
package
{
public class Singleton
{
private static var _instance:Singleton;
private static var _okToCreate:Boolean = false;
public function Singleton()
{
if( !_okToCreate ){
throw new Error("Error: " + this +
" is not a singleton and must be " +
"accessed with the getInstance() method");
}
}
public static function getInstance():Singleton
{
if( !Singleton._instance ){
_okToCreate = true;
_instance = new Singleton();
_okToCreate = false;
}
return _instance;
}
}
}
function removeDuplicate(arr:Array) : void{
var i:int;
var j: int;
for (i = 0; i < arr.length - 1; i++){
for (j = i + 1; j < arr.length; j++){
if (arr[i] === arr[j]){
arr.splice(j, 1);
}
}
}
}
var arr:Array = new Array("a", "b", "a", "c", "d", "b");
removeDuplicate(arr);
package {
import flash.media.Camera;
import flash.media.Video;
public class CameraDemo extends Video {
private var camera:Camera;
private var camQuality:int = 80;
private var fps:int = 30;
public function CameraDemo(w:Number = 640, h:Number = 480) {
/* Set the width and height of the camera's display */
this.width = w;
this.height = h;
startCamera();
}
public function startCamera():void
{
/* Get the default camera for the system */
camera = Camera.getCamera();
/* Set the bandwidth and camera image quality */
camera.setQuality(0, camQuality);
/* Set the size of the camera and frames per second */
camera.setMode(this.width, this.height, fps);
/* Attach the camera to the video object.. In this case the current class. */
this.attachCamera(camera);
}
}
}