Friday, 3 July 2009

Full screen in Actionscript 3

Since Actionscript 2.0 your SWF files could be viewed in full screen using the stage.displayState function. In Actionscript 3.0, the exact same function is still available to use. This tutorial will teach you how to use the full screen mode using a basic button in Actionscript 3.0. For more information checkout the full screen mode on the Adobe website.

Full screen in Actionscript 3

Step 1

Create a new Flash AS3 File.
Create your button on the stage. I have created a basic rectangle shape with the message “full screen”, but you can create whatever kind of button shape you wish. Give your button the instance name “button1”. If you don’t know how to create buttons then checkout the basic buttons tutorial.





Step 2

On the timeline insert a new layer called “Actions”. Then right click on the first frame and select Actions and enter the following code:

//1.
function setFullScreen():void {
if (stage.displayState== "normal") {
stage.displayState="fullScreen";
stage.scaleMode = StageScaleMode.NO_SCALE;
} else {
stage.displayState="normal";
}
}

//2.
button1.addEventListener(MouseEvent.CLICK, goFull);

//3.
function goFull(event:MouseEvent):void {
setFullScreen();
}

Code:
1. This is a function for toggling in between full screen mode and normal mode. I have also included the “stage.scaleMode” function which maintains the size of the objects on the stage. If you comment this out, the objects on the stage will increase in size when you go into full screen mode.
2. Event listener for detecting mouse clicks with the parameter goFull. The code assumes you have the instance name “button1”.
3. This triggers the function “goFullScreen” which displays the SWF in the full screen mode.


When you embed your flash SWF into the html page you need to include the parameter “allowFullScreen” and the value “true” like below:

E.g. param name= “allowFullScreen” value= “true”

Note that when you test the full screen mode in Flash it will not work, as you will need to embed the SWF into the html. Although it will work if you publish the SWF then run it from the directory. When you are in full screen mode all keyboard inputs are disabled apart from the Escape key which ends the full screen mode.

The source files can be downloaded here.

3 comments:

Doctor 5 February 2010 at 03:10  

This is the most clear and simple explanation of doing full-screen in Flash that I've seen. Thank you!

kaka 16 May 2010 at 23:17  

nice example, i really need it

Ehsan 9 July 2011 at 18:13  

say i have two video frame and two full screen button. What i need to modify? please give me a solution.

thanks

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP