- really helps me on doing my ever first you tube like website.
Since the Flash Player 9,0,28,0 update, flash applets can go to true full-screen. There are no fancy javascript hacks needed either.
Users can toggle between normal size and fullscreen with a simple click, which can toggle Stage["displayState"] from "normal" to "fullScreen".
The param allowFullScreen must be set to true in the applet html.
<param name="allowFullScreen" value="true" />
The first thing to do is create a button and add the following code to it:
- on(press){
- toggleFullScreen();
- }
The code for the function toggleFullScreen and a resize listener are placed on the main stage.
- //Don't scale the movie when the stage size changes
- Stage.scaleMode="noScale";
- //Align the stage to the top left
- Stage.align = "TL";
- //Function to toggle between fullscreen and normal size
- //the toggle fullscreen button calls this function when pressed
- function toggleFullScreen(){
- //if normal size, go to fullscreen, else go to normal size
- if(Stage["displayState"]=="normal"){
- Stage["displayState"]="fullScreen";
- }else{
- Stage["displayState"]="normal";
- }
- }
- //Create a listener for each time the Stage is resized
- var resizeListener:Object = new Object();
- //Called each time the stage is resized
- resizeListener.onResize = function () {
- //Move the button to the center of the screen
- toggleFullScreenButton._x=Stage.width/2;
- toggleFullScreenButton._y=Stage.height/2;
- }
- //Add the listener to Stage
- Stage.addListener(resizeListener);
Example XHTML used for this applet:
<object data="http://www.bezzmedia.com/swfspot/resources/34-fullscreen.swf"
type="application/x-shockwave-flash" width="400" height="200" >
<param name="movie" value="http://www.bezzmedia.com/swfspot/resources/34-fullscreen.swf" />
<param name="allowFullScreen" value="true" />
</object>
The balls were added in to show that the stage extends to the borders of the screen, even when resized.
Download the source file below:
Download Source File
No comments:
Post a Comment