我创建了一个视频播放器,但需要添加一个按钮,单击此按钮可将视频置于全屏查看模式。我不想扩展舞台上的所有内容 - 只是视频。我似乎无法找到如何做到这一点 - 我认为这很容易。
答案 0 :(得分:2)
看看是否有效:
stage.displayState = StageDisplayState.FULL_SCREEN;
videoPlayer.x = 0;
videoPlayer.y = 0;
//save the width and height in temp vars
//for restoring them later.
videoPlayer.width = stage.fullScreenWidth;
videoPlayer.height = stage.fullScreenHeight;
答案 1 :(得分:1)
我的理解是,您只能将整个舞台设置为全屏,而不是选择性地设置元素,因为您有效地在显示树的根部放大舞台对象。实现您正在寻找的效果的最佳方法是安排/隐藏/显示您不希望在FullScreenEvent.FULL_SCREEN事件处理程序中可见的任何对象。
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/FullScreenEvent.html
此外,舞台文档displayState section中的相关信息:
全屏模式下电影的缩放行为由scaleMode设置决定(使用Stage.scaleMode属性或HTML文件中的SWF文件的嵌入标记设置进行设置)。如果在应用程序转换为全屏模式时将scaleMode属性设置为noScale,则会更新舞台宽度和高度属性,并且舞台将调整resize事件。
答案 2 :(得分:1)
最近碰到了这个问题,这就像魅力一样。所以把它放在这里以防它对任何人都有帮助。
Flex客户端代码:
private function startFullScreen(event:MouseEvent):void
{
videoHolder.removeChild(vid); //videoHolder is an spark VideoDisplay
Component
this.stage.addChild(vid);
this.stage.displayState = StageDisplayState.FULL_SCREEN;
oldWidth = vid.width; //store old values required while going back
oldHeight = vid.height;
vid.width = this.stage.width;
vid.height = this.stage.height;
this.stage.addEventListener(FullScreenEvent.FULL_SCREEN,fullScreenHandler);
}
}
/* handler for Fullscreen */
private function fullScreenHandler(event:FullScreenEvent):void
{
//This function is called when user presses Esc key
//on returning to normal state, add the video back
if(!event.fullScreen)
{
this.stage.removeChild(vid);
videoHolder.addChild(vid);
vid.width = oldWidth;
vid.height = oldHeight;
this.stage.removeEventListener(FullScreenEvent.FULL_SCREEN,fullScreenHandler )
}
}
答案 3 :(得分:0)
如果舞台上的元素正在缩放,则听起来好像您正在使用fullScreenRect属性而不是简单地指示舞台对象进入全屏模式。
Amarghosh有正确的方法,但通过附加听众可以使其变得更加灵活:
stage.addEventListener(Event.RESIZE, _onStageResize, false, 0, true);
stage.displayState = StageDisplayState.FULL_SCREEN;
private function _onStageResize(event:Event):void
{
if(stage.displayState == StageDisplayState.FULL_SCREEN)
{
// Proportionally resize your video to the stage's new dimensions
// i.e. set its height and width such that the aspect ratio is not distorted
}
else
{
// Restore the normal layout of your elements
}
}
答案 4 :(得分:0)
进入全屏模式
var fullScreenButton:Button = new Button();
...
addChild(fullScreenButton);
fullScreenButton.addEventListener(MouseEvent.CLICK, fullScreenButtonHandler);
...
private function fullScreenButtonHandler(event:MouseEvent)
{
var screenRectangle:Rectangle = new Rectangle(video.x, video.y, video.width, video.height);
stage.fullScreenSourceRect = screenRectangle;
stage.displayState = StageDisplayState.FULL_SCREEN;
}
退出全屏模式
...
stage.displayState = StageDisplayState.NORMAL;
...
注意:您也可以按下转义。