FullScreen in Flash CS4 / AS3

If you want enable fullscreen modality in Flash CS 4 and ActionScript 3.0 you need to following steps:
1) Modify the displayState property to StageDisplayState.FULL_SCREEN costant to enable it, and to StageDisplayState.NORMAL to come back to 'normal' modality
2) Enable the 'allowfullscreen' attribute in your html code (see below)

...
<param name="allowFullScreen" value="true" />...
and
<embed src="index.swf" allowfullscreen="true"></embed>


HOW CREATE A FULLSCREEN BUTTON in AS3

The script is quite simple and is fullCommented.
You just need to create a Flash CS3/4 ActionScript 3.0 file and link the document Class to the FullScreenMain.as class.
We add to the display list a Button Flash Component, so we need to import its assets to the .fla dragging it from the Component panel to the library.
package {

import flash.display.MovieClip;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.StageDisplayState

import fl.controls.Button;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.FullScreenEvent;


public class FullScreenMain extends MovieClip {

// The FullScreen Button
private var fullScreen_btn:Button;

// Save the fullScreen status
private var fullScreenStatus:Boolean;


/**
* Constructor
*/
public function FullScreenMain() {

// Create the FullScreen Button (add to the .fla library the button component assets)
fullScreen_btn = new Button();
fullScreen_btn.label = "Enable FULL_SCREEN";
fullScreen_btn.width = 150;
fullScreen_btn.x = 120;
fullScreen_btn.y = 50;
addChild(fullScreen_btn)


// Set NO_SCALE because we don't want that when fullscreen is enable movieclips are scaled too
var swfStage:Stage = this.stage;
swfStage.scaleMode = StageScaleMode.NO_SCALE;
swfStage.align = StageAlign.TOP_LEFT;

// Registriamo un listener per la modalitÃÆ’Æ’ÃÆââ‚
¬â„¢ÃƒÆ’†â€™ÃƒÂ¢Ã¢â€šÂ¬ ââ‚Ãââ‚
¬Å¡Ãƒâ€šÃ‚¬ÃƒÆ’¢â€žÂ¢ FULLSCREEN:

// Listener for FullScreen Button
fullScreen_btn.addEventListener(MouseEvent.CLICK, changefullScreenStatus)


// Listener for FullScreen event. It's invoked every time the 'displayState' property change
fullScreen_btn.stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenRedraw);


}





/**
* Check the fullScreenStatus and Enabled / Disable the FullScreen
*/
private function changefullScreenStatus(e:MouseEvent):void
{
// Disable FullScreen if enabled, and viceversa
if(fullScreenStatus)
fullScreen_btn.stage.displayState = StageDisplayState.NORMAL;
else
fullScreen_btn.stage.displayState = StageDisplayState.FULL_SCREEN;


}

/*
* Invoked at every 'displayState' property change
*/
function fullScreenRedraw(event:FullScreenEvent):void
{
// Check if fullScreen is enabled and uptades properties
if (event.fullScreen)
{
fullScreen_btn.label = "Disable FULL_SCREEN";
fullScreenStatus = true;
}
else
{
fullScreen_btn.label = "Enable FULL_SCREEN";
fullScreenStatus = false;
}

}


}
}

Comments on this post

nkzvTg <a href="http://nfumurrrsdeh.com/">nfumurrrsdeh</a>, pcsfrgcqlfga, [link=http://ejhrgjjwyyxw.com/]ejhrgjjwyyxw[/link], http://aqaoaazbfxfv.com/

Post a comment

Embed any code between [code] [/code] tags
captcha image   Reload