0

我正在使用 YouTube 嵌入 API ( https://developers.google.com/youtube/flash_api_reference ) 在 swf 文件中流式传输 YouTube 剪辑。我在 YouTube 剪辑的顶部放置了一个透明按钮,但是一旦加载,嵌入的剪辑就会继续出现在按钮上。

如何更改图层顺序以使按钮始终位于顶部?

这是我嵌入 YouTube 剪辑的 AS3 代码……</p>

// This will hold the API player instance once it is initialized.
var player:Object;

var loader:Loader = new Loader();

var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = true;
context.securityDomain = SecurityDomain.currentDomain;
context.applicationDomain = ApplicationDomain.currentDomain;

loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
Security.allowDomain("www.youtube.com")
loader.load(new URLRequest("http://www.youtube.com/v/Z3wnzmJBCDo?version=3&rel=0&autoplay=1&controls=1&showinfo=0&modestbranding=1"));

function onLoaderInit(event:Event):void {
    addChild(loader);
    loader.content.addEventListener("onReady", onPlayerReady);
    loader.content.addEventListener("onError", onPlayerError);
    loader.content.addEventListener("onStateChange", onPlayerStateChange);
    loader.content.addEventListener("onPlaybackQualityChange", onVideoPlaybackQualityChange);
}

function onPlayerReady(event:Event):void {
   // Event.data contains the event parameter, which is the Player API ID
trace("player ready:", Object(event).data);

// Once this event has been dispatched by the player, we can use
// cueVideoById, loadVideoById, cueVideoByUrl and loadVideoByUrl
// to load a particular YouTube video.
player = loader.content;
// Set appropriate player dimensions for your application
player.setSize(300, 250);

}

function onPlayerError(event:Event):void {
// Event.data contains the event parameter, which is the error code
trace("player error:", Object(event).data);
}

function onPlayerStateChange(event:Event):void {
// Event.data contains the event parameter, which is the new player state
trace("player state:", Object(event).data);
}

function onVideoPlaybackQualityChange(event:Event):void {
// Event.data contains the event parameter, which is the new video quality
trace("video quality:", Object(event).data);
}

非常感谢,

詹姆士

4

1 回答 1

0

考虑创建两个容器 - 一个用于您的自定义项目,一个用于 youtube 播放器。

var myLittleCustomContainer:Sprite = new Sprite();
var youtubeContainer:Sprite = new Sprite();

addChild(youtubeContainer);
addChild(myLittleCustomContainer);

...
function onLoaderInit(event:Event):void {
    youtubeContainer.addChild(loader);
    loader.content.addEventListener("onReady", onPlayerReady);
    loader.content.addEventListener("onError", onPlayerError);
    loader.content.addEventListener("onStateChange", onPlayerStateChange);
    loader.content.addEventListener("onPlaybackQualityChange", onVideoPlaybackQualityChange);
}
....

您可以随时随地添加对象,如下所示:

myLittleCustomContainer.addChild(YOUR_DISPLAY_OBJECT);

并且会出现在玩家面前

于 2013-09-02T12:16:50.577 回答