2013-04-02 104 views
2

我有一个Youtube视频在Flash中播放,但我想将它集中到舞台上。此刻它要么到达左上角,要么到达右下角。我到处搜索寻找答案,但我找不到任何帮助我的东西。希望你们中的一个能够提供一些见解?无法将Youtube播放器集中到Flash CS5(AS3)的舞台

下面是我加载播放器和视频的代码。视频没有问题,我只是想把它放在舞台上。

stop(); 

Security.allowDomain("www.youtube.com"); 

var my_player:Object; 

var my_loader:Loader = new Loader(); 
my_loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3")); 
my_loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit); 

function onLoaderInit(e:Event):void{ 
addChild(my_loader); 
my_player = my_loader.content; 
my_player.addEventListener("onReady", onPlayerReady); 
} 

function onPlayerReady(e:Event):void{ 
my_player.setSize(600,300); 
my_player.cueVideoById("76BboyrEl48",0); 
my_player.x = stage.stageWidth/2; 
my_player.y = stage.stageHeight/2; 
} 

play_btn.addEventListener(MouseEvent.CLICK, playVid); 
function playVid(e:MouseEvent):void { 
my_player.playVideo(); 
} 
pause_btn.addEventListener(MouseEvent.CLICK, pauseVid); 
function pauseVid(e:MouseEvent):void { 
my_player.pauseVideo(); 
} 

正如你可以看到我已经尝试使用.x = stageWidth/2;方法,但只是将玩家移到右下角,没有它,它会停留在左上角。

任何帮助将不胜感激。感谢提前:)

+0

尝试'my_player.x = stage.stageWidth/2 - my_player.width/2;' – Smolniy

+0

@Smolniy,完美的工作!我知道这将是一些简单的解决方案,但我无法看到它。非常感谢你:) – ElighWarrior

回答

0

试试这个:

my_player.x = stage.stageWidth/2 - my_player.width/2; 
my_player.y = stage.stageHeight/2 - my_player.height/2; 
+0

非常感谢你的回应!工作了一种享受:) – ElighWarrior

+0

不要忘记接受答案,如果它帮助:) – GeorgeCross

+0

对不起。我是一个长期的潜伏者,第一次海报:P不真的知道网站的规则呢:) – ElighWarrior