本文和大家重点讨论一下Flex全屏的原理和局部Flex全屏的几种方法,Flex全屏和flash全屏其实是相似的,都是由as控制的,当选择以Flex全屏 显示的时候,会自动更改swf的高和宽,以Flex全屏 幕显示整个swf。
Flex全屏
1.Flex全屏的原理:
Flex全屏和flash全屏其实是相似的,都是由as控制的,当选择以Flex全屏显示的时候,会自动更改swf的高和宽,以Flex全屏幕显示整个swf。
2.局部Flex全屏的两种方法:
一、使用在flash.display包中有一个stage对象,它有一个属性是fullScreenSourceRect:Rectangle,设置FlashPlayer以将特定的舞台区域放大到Flex全屏模式。
二、Flex全屏时调整某组件的高度和宽度,铺满整个屏幕,当退出Flex全屏时,要还原组件的高度和宽度。
3.Flex全屏的代码实现:
第一种方法:
- //valid,willenablehardwarescaling
- stage.fullScreenSourceRect = newRectangle (0,0,320,240);——详细代码可以查看 Flex帮助
第二种方法:(注意:在Application中添加的初始化函数,使用的是applicationComplete事件)
- xmlversion xmlversion ="1.0" encoding ="utf-8" ?>
- < mx:Applicationxmlns:mx mx:Applicationxmlns:mx ="http://www.adobe.com/2006/mxml" layout ="vertical"
- applicationComplete ="init(event)" viewSourceURL ="srcview/index.html" >
- < mx:Script >
- importflash.display.StageDisplayState;
- privatefunctioninit(evt:Event):void{
- /*Setupfullscreenhandler.*/
- Application.application.stage.addEventListener(FullScreenEvent.FULL_SCREEN,fullScreenHandler);
- dispState=Application.application.stage.displayState;
- }
- privatefunctionfullScreenHandler(evt:FullScreenEvent):void{
- dispState=Application.application.stage.displayState+"(fullScreen="+evt.fullScreen.toString()+")";
- if(evt.fullScreen){
- /*Dosomethingspecifichereifweswitchedtofullscreenmode.*/
- }else{
- /*Dosomethingspecifichereifweswitchedtonormalmode.*/
- }
- }
- privatefunctiontoggleFullScreen():void{
- try{
- switch(Application.application.stage.displayState){
- caseStageDisplayState.FULL_SCREEN:
- /*Ifalreadyinfullscreenmode,switchtonormalmode.*/
- Application.application.stage.displayState=StageDisplayState.NORMAL;
- break;
- default:
- /*Ifnotinfullscreenmode,switchtofullscreenmode.*/
- Application.application.stage.displayState=StageDisplayState.FULL_SCREEN;
- break;
- }
- }catch(err:SecurityError){
- //ignore
- }
- }
- ]]>
- mx:Script >
- < mx:Stringid mx:Stringid = "dispState" />
- < mx:Labeltext mx:Labeltext = "width={Application.application.width}" />
- < mx:Labeltext mx:Labeltext = "height={Application.application.height}" />
- < mx:Labeltext mx:Labeltext = "displayState={dispState}" />
- < mx:Buttonlabel mx:Buttonlabel ="Togglefullscreen" click ="toggleFullScreen()" />
- mx:Application >
--------------------------------------------------并修改index.template.html:-------------------------------------------
- AC_FL_RunContent(
- "src","main",
- "width","100%",
- "height","100%",
- "align","middle",
- "id","main",
- "quality","high",
- "bgcolor","#869ca7",
- "name","main",
- "allowScriptAccess","sameDomain",
- "type","application/x-shockwave-flash",
- "pluginspage","http://www.adobe.com/go/getflashplayer",
- "allowFullScreen","true"
- );
注意:
1、Application.application.stage.displayState=StageDisplayState.FULL_SCREEN;
//必须把它放到按钮或键盘事件中,否则在AS2.0里会被忽略,AS3.0里会抛出以下异常SecurityError:Error#2152:不允许使用Flex全屏模式。atflash.display::Stage/setdisplayState()
2、Flex全屏下Flash文本框无法输入,设计界面请勿支持Flex全屏,而且Flex全屏下做不到屏蔽右键的功能
本文摘自:http://developer.51cto.com/art/201008/216028.htm