开发者

Problems Displaying Profile Picture in Flash swf

I followed this tutorial Loading Facebook Profile Picture Into Flash SWF Using Graph API to get the users profile picture to show in my flash game, but I'm having some issues.

import com.facebook.graph.Facebook;
import com.facebook.graph.data.FacebookSession;
import com.facebook.graph.net.FacebookRequest;

import flash.events.Event;
import flash.events.IOErrorEvent;

//place your APP ID here
const APP_ID:String = "app_id";

//Initialize facebbok library
Facebook.init(APP_ID, HandleLogin);

function HandleLogin(response:Object, fail:Object):void
{
    if(Facebook.getSession().accessToken)
    {
        LoadMyInfo();
        LoadMyPicture();
    }
}

function LoadMyInfo():void
{
    Facebook.api("/me", MyInfoLoaded);
}

function MyInfoLoaded(response:Object, fail:Object):void
{
    nameTextField.text = response.name;
}

function LoadMyPicture():void
{
    debug.text = "Entered loadMyPicture() function ";

    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, MyPictureLoaded, false, 0, true);

    var request:URLRequest = new URLRequest("facebookProxy.php");
    var variables:URLVariables = new URLVariables()开发者_C百科;

    variables.path = Facebook.getImageUrl(String(Facebook.getSession().uid), 'large');

    debug.appendText(" \nvariables.path: " + String(variables.path));

    request.data = variables;

    debug.appendText(" \nrequest.data: " + String(request.data))

    loader.load(request);

    debug.appendText(" \n" + String(loader.load(request)));
}

function MyPictureLoaded(event:Event):void 
{
    debug.appendText(" \nEntering MyPictureLoaded");

    var loader:Loader = event.target.loader;
    loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, MyPictureLoaded);
    loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, MyPictureLoadError);        
    var bitmap = Bitmap(loader.content);
    bitmap.smoothing = true;

    //Note: picturePlaceholder is just a blank movie clip on the Stage
    bitmap.x = picturePlaceHolder.x;
    bitmap.y = picturePlaceHolder.y;
    bitmap.width = picturePlaceHolder.width;
    bitmap.height = picturePlaceHolder.height;
    picturePlaceHolder.addChild(bitmap);

    debug.appendText(" \nBitmap is null: " + String(bitmap == null) +
                     " \nBitmap X: " + String(bitmap.x) + " Bitmap Y: " + String(bitmap.y) +
                     " \nBitmap width: " + String(bitmap.width) +
                     " \nBitmap height: " + String(bitmap.height))
}

function MyPictureLoadError(e:IOErrorEvent):void
{
    debug.appendText("Loading Error");
}

This is what my code looks like after following the tutorials on the link above. With the debug I noticed that the function MyPictureLoaded is never called.

They never specified where I would call the function LoadMyPicture. I assumed it would go together with LoadMyInfo so I placed it there. They have a working example but no source code, so I'm hope someone here would shed some light on this.

EDIT 1

Here is what it looks like when I put it up on facebook. The last line debug.appendText(" \n" + String(loader.load(request))); is outputting undefined. I also made a change in the variables.path = Facebook.getImageUrl(String(Facebook.getSession().uid), 'large'); I added (String(), 'large') because in the docs it saying to pass strings into there. Edit: I realized adding String() is pointless.


var request:URLRequest = new URLRequest("facebookProxy.php");

Did you do the part of the tutorial that writes a server-side PHP proxy loader on your server?

If you don't have a file named facebookProxy.php on your server where you run this it won't work (the code is requesting "./facebookProxy.php" which probably doesn't exist). If you want to run this in the debugger on your local machine, you will need to make that file in the same directory as your swf and make sure you have apache/php running on your localhost.

If that's too much work for you, I would suggest following some of the examples from the API' project page: http://code.google.com/p/facebook-actionscript-api/downloads/detail?name=GraphAPI_Examples_1_6.zip&can=2&q=

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜