I'm trying to implement the 1.6 Mobile Facebook API (http://code.google.com/p/facebook-actionscript-api/downloads/detail?name=GraphAPI_Mobile_1_6.swc) into an Air for Android application. I've succesfully used the Web and Desktop API's however with the mobile app it's expecting an extra parameter to a stageReference, see:
login(callback:Function, stageRef:Stage, extendedPermissions:Array, webView:StageWebView = null)
But, using i'm using Flex and not Flash CS5, i can't just pass in this.stage or this or anything like that.
What exactly would you guys think I need to pass into that using Flash builder Flex? I can't seem to find any examples for the mobile actionscript API so i'm kinda in the dark, anyone have any ideas?
Here's the login information from the Mobile API Docs:
login () method
public static function login(callback:Function, stageRef:Stage, extendedPermissions:Array, webView:StageWebView = null):void
Opens a new login window so the current user can log in to Facebook.
Parameters
callback:Function — The method to call when login is successful. The handler must have the signature of callback(success:Object, fail:Object); Success will be a FacebookSession if successful, or null if not.
stageRef:Stage — A reference to the stage
extendedPermissions:Array — (Optional) Array of extended permissions to ask the user for once they are logged in.
webView:StageWebView (default = null) — (Optional) The instance of StageWebView to use for the login window For the most current list of extended permissions, visit http://developers.facebook.com/docs/authentication/permissions
If you're using Flex, you have FlexGlobals.topLevelApplication
which will point to your mx:Application
or s:Application
so you can call stage
on that to get a reference to it.
Otherwise, any DisplayObject
attached to the stage or attached to another DisplayObject
attached to the stage
, will have it's stage
property set (If it's not attached to anything, stage
will be null
).
Other than that, normally what people do is keep a static somewhere that they can access through the code, that's set when the program starts. For example, your typical main class could be something like:
package
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
public class Main extends Sprite
{
public static var stage:Stage = null;
public function Main():void
{
// if we have our stage, go directly to _init(), otherwise wait
if ( this.stage ) this._init();
else this.addEventListener( Event.ADDED_TO_STAGE, this._init );
}
private function _init( e:Event = null ):void
{
// remove the listener
this.removeEventListener( Event.ADDED_TO_STAGE, this._init );
// hold the stage
Main.stage = this.stage;
// do everything else
...
}
}
}
After that, anywhere in your code, you can call Main.stage
to get access to the stage
.