android - 如何引用阶段?使用 flex for Facebook actionscript 移动 API 登录方法

标签 android flash apache-flex facebook stage

我正在尝试将 1.6 Mobile Facebook API ( http://code.google.com/p/facebook-actionscript-api/downloads/detail?name=GraphAPI_Mobile_1_6.swc ) 实现到 Air for Android 应用程序中。我已经成功地使用了 Web 和桌面 API,但是对于移动应用程序,它期望 stageReference 有一个额外的参数,请参阅:

login(callback:Function, stageRef:Stage, extendedPermissions:Array, webView:StageWebView = null)

但是,如果我使用的是 Flex 而不是 Flash CS5,我不能只传入 this.stage 或 this 或类似的东西。

你们认为我需要使用 Flash builder Flex 传递什么?我似乎找不到移动 ActionScript API 的任何示例,所以我有点一头雾水,有人有什么想法吗?

这是移动 API 文档中的登录信息:

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

最佳答案

如果您使用的是 Flex,您有 FlexGlobals.topLevelApplication 它将指向您的 mx:Applications:Application 所以您可以对其调用 stage 以获取对它的引用。

否则,附加到舞台或附加到附加到 stage 的另一个 DisplayObject 的任何 DisplayObject 都将具有 stage 属性集(如果它没有附加到任何东西,stage 将为 null)。

除此之外,通常人们所做的是在他们可以通过代码访问的地方保持静态,这是在程序启动时设置的。例如,您典型的主类可能是这样的:

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
            ...
        }

    }

}

之后,您可以在代码的任何位置调用 Main.stage 来访问 stage

关于android - 如何引用阶段?使用 flex for Facebook actionscript 移动 API 登录方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5574640/

相关文章:

java - 缩放 ImageButton 以适应各种屏幕尺寸

java - android studio 不断将我的所有输出消息大写?

android - 不同的 Android 手机对它们可以连接的蓝牙 SPP 配置文件设备的数量有不同的限制吗?

flash - AS3 中的 URL 编码变量?

android - Adobe Flex Mobile 4.6 - 从浏览器启动应用程序

android - 无法在 iOS 上与 Bing Map 交互; Android 不显示折线(Flex 移动应用程序,通过 StageWebView 使用 Javascript API)

regex - 正则表达式大写到小写

android - Realm.init() 无法解析方法 init 在应用程序 onCreate 中不起作用?

android - actionscript3计算器声音播放

actionscript-3 - 如何将文本字段居中并在末尾添加空格?