2011-03-01 92 views
0

我按照本教程Loading Facebook Profile Picture Into Flash SWF Using Graph API獲取用戶配置文件圖片以顯示在我的Flash遊戲中,但我遇到了一些問題。在Flash中顯示配置文件圖片的問題swf

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(); 

    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"); 
} 

這是我的代碼在上面的鏈接上的教程後看起來像什麼。通過調試,我發現從未調用函數MyPictureLoaded

他們從未指定我要調用函數的位置LoadMyPicture。我認爲它會一起LoadMyInfo所以我把它放在那裏。他們有一個工作的例子,但沒有源代碼,所以我希望這裏有人會對此有所瞭解。

編輯1

Here是個什麼樣子,當我把它在Facebook上一樣。最後一行debug.appendText(「\ n」+ String(loader.load(request)));正在輸出未定義。我也在variables.path = Facebook.getImageUrl(String(Facebook.getSession()。uid),'large');我添加了(String(),'large'),因爲它在文檔中表示要將字符串傳遞到那裏。 編輯:我意識到添加String()是毫無意義的。

回答

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

你這樣做,你的服務器上寫了一個服務器端的PHP代理裝載機教程的一部分嗎?

如果您在運行此服務器的服務器上沒有名爲facebookProxy.php的文件,則該文件將無法工作(代碼請求的「./facebookProxy.php」可能不存在)。如果你想在本地機器上的調試器中運行它,你將需要在swf文件所在的目錄下創建該文件,並確保你的本地主機上運行了apache/php。

如果這對你太辛苦了,我建議以下一些來自API的例子」項目頁面:http://code.google.com/p/facebook-actionscript-api/downloads/detail?name=GraphAPI_Examples_1_6.zip&can=2&q=

+0

我確實有facebookProxy.php在保存文件夾爲我的swf文件是我的服務器上。哪個例子可以幫助我更好地使用該zip文件? – RamenNoodles 2011-03-02 13:41:27

+0

FlashWebExample文件夾可能與您正在做的最接近。 – 2011-03-02 17:45:23

+0

嗯似乎我遇到的問題是越來越這** loader.contentLoaderInfo.addEventListener(Event.COMPLETE,MyPictureLoaded,假,0,真); **執行。當函數MyPictureLoaded運行但調試從不出現時,我有一個調試顯示。所以我可能不得不提出一個新問題。 – RamenNoodles 2011-03-02 18:25:24