2

我正在尝试将 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 传递什么?我似乎找不到移动操作脚本 API 的任何示例,所以我有点不知所措,有人有什么想法吗?

以下是来自 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
4

1 回答 1

2

如果您使用的是 Flex,您有FlexGlobals.topLevelApplicationwhich 将指向您的mx:Applicationor s:Application,因此您可以调用stage它来获取对它的引用。

否则,任何DisplayObject附加到舞台或附加到另一个DisplayObject附加到 的stage,都将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.

于 2011-04-07T08:02:38.237 回答