1

我在 AS3 中设置了 Youtube API - 一切都加载得很好,但我想加载多个缩略图,然后显示它们,以便用户可以单击一个来观看视频,但我在执行此操作时遇到了一些麻烦。

我这样做的代码是这样的:(其中“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;
   }

现在如何让它显示我的数组结果?

4

1 回答 1

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):

在此处输入图像描述

于 2013-09-24T17:57:11.577 回答