将youtube视频嵌入到Flash项目中并在AS3中调整其大小

时间:2017-06-27 06:26:25

标签: actionscript-3 flash flash-cs6

您好我试图使用as3.0将YouTube视频嵌入到我的Flash项目中。到目前为止,我已经能够将视频播放到我的画面并进行播放。但我的舞台大小是500X500。所以我需要我的视频宽度:300和高度:150。我尝试更改视频大小,但这对我不起作用。该视频具有原始嵌入宽度和高度......那么我该怎么做呢?

这是我的代码。

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/yNfkNWfH6aU?version=3"));

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, 150);
    //player.x = stage.width/2; //puts the video horizontally centered
    //player.y = stage.width/2; //puts the video vertically centered
    //player.x=100;
    //player.width=265;
    //player.height=200;
}

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

0 个答案:

没有答案