2013-09-23 118 views
1

我已經在AS3的Youtube API設置 - 它都加載很好,但我想加載多個縮略圖,然後顯示它們,以便用戶可以點擊一個觀看視頻,但我'這樣做有點麻煩。Youtube API Actionscript 3和縮略圖

,我有這樣做的代碼是這樣的:(其中「vid_player」是我的容器對象的實例名稱

function createFeaturedButtons(vid_player:Object, featuredVideos:Array) { 
    var results:Array = []; 
    for each (var id:String in featuredVideos) { 
    results.push(vid_player.getClickToPlayButton("BYjoERBzfNw")); 
results.push(vid_player.getClickToPlayButton("oEB50roGOOg")); 
    } 
    return results; 
    } 

現在我怎麼得到它顯示我的我的數組的結果? 。

+0

更多參考我的代碼視圖:http://stackoverflow.com/questions/18926908/as3-and-youtube-api-default-youtube-buttons我有默認的按鈕顯示現在使用:http://www.youtube .com/v/ID?version = 3 – user2561920

回答

2

這應該讓你的縮略圖,並與各間5個像素添加到舞臺的顯示列表中排在idArray項目的數量定義的按鈕將如何加載:

var spacing:Number = 5; 
var nextX:Number = 0; 
var idArray:Array = [ 'BYjoERBzfNw', 'oEB50roGOOg', 'oEB50roGOOg', 'oEB50roGOOg', 'oEB50roGOOg' ]; 

// this call needs to be made in the onPlayerReady() method (not listed in this example but part of the youtube player initialization process) 
createThumbnails(vid_player, idArray); 

function createThumbnails(vid_player:Object, videoIdArray:Array) 
{ 
    var i:int; 
    var results:Array = []; 

    for(i = 0; i < videoIdArray.length; i++) 
    { 
     results.push(vid_player.getClickToPlayButton(videoIdArray[ i ])); 
    } 

    for(i = 0; i < results.length; i ++) 
    { 
     // set whatever width and height you want the thumb to be 
     results[ i ].width = 50; 
     results[ i ].height = 50; 

     // set its position 
     results[ i ].x = nextX; 
     // set the next position 
     nextX += results[ i ].width + spacing; 

     addChild(results[ i ]); 
    } 
} 

從此程序,當添加到加載成功的球員,(用我自己的視頻ID)代碼的輸出看起來像下面,(我用所有5個大拇指相同的ID):

enter image description here

+0

你認爲你可以澄清一點嗎?這產生了一個錯誤:未定義的屬性訪問idArray(也我假設我切換在這一行的實際「ID」:results.push(vid_player.getClickToPlayButton(id));) – user2561920

+0

好吧,所以我得到的錯誤被消除增加:var idArray:Array;在我的代碼的頂部 - 但我仍然看不到縮略圖。我覺得我只是在這裏錯過了一些小東西 - 非常感謝你的幫助! – user2561920

+0

我推測你已經收集了你的視頻ID在一個數組中。您需要傳遞createFeaturedButtons()作爲第二個參數的視頻ID數組。我也改變了createButtons循環。查看代碼編輯。 – Ribs