6 Replies Latest reply: Apr 5, 2012 11:09 AM by sinious RSS

    Fullscreen button in Actionscript 2

    Cuwen

      Hi everyone.  I hope someone can help me with this.  I'm having some problems making a fullscreen button in Actionscript 2 that works in a swf file.  You see, this document I'm making isn't going to be going on the web.  It's just going to be shown on a computer at company events.  However, I need a button that makes the document fullscreen, and none of the codes I've tried have seemed to work in the swf.  Here is the current code I'm working with:

       

      //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);

        • 1. Re: Fullscreen button in Actionscript 2
          sinious MVP

          How you're doing it is fine. Chances are you might be accidently removing the listener from your button (say your button goes off the timeline and is reinstantiated because of a keyframe) and it no longer is assigned to that function. You should run it in the flash IDE and put a trace("Button Pressed"); in the button function just to see if the assignment is still valid when you think it should be.

          • 2. Re: Fullscreen button in Actionscript 2
            Cuwen Community Member

            ... I have no idea how to do that. lol.  I'm sorry.  I'm pretty good with Flash, but all that other stuff I'm not sure how to do.  And the thing is, I got that code from a document online that was free.  That didn't even work for me when I viewed the swf.  I pushed the button and it didn't go fullscreen.  So, it's not just my document.  I'm sorry.  I should have added that to my original post.

            • 3. Re: Fullscreen button in Actionscript 2
              sinious MVP

              I see you are setting a listener on "toggleFullScreenButton". I assume this is the instance name of your button? How did you assign "toggleFullScreenButton" to the function "toggleFullScreen()"?

               

              On the trace, just change the function like so:

               

              function toggleFullScreen(){

                   // add a trace which appears in the output panel when you "TEST" your movie (e.g. CTRL+ENTER inside Flash)

                   trace("Toggle full screen button was pressed");

               

                   if (Stage.displayState == "normal") { Stage.displayState = "fullscreen"; }

                   else { Stage.displayState = "normal"; }

              }

               

              You must test the movie inside flash (CTRL or CMD + ENTER). Then you will see that message appear in the output panel when you press yout button. If you don't see the message you know you have an issue with assigning that button to the function toggleFullScreen();

              • 4. Re: Fullscreen button in Actionscript 2
                Cuwen Community Member

                I got this compiler error: 

                Scene=Scene 1, layer=Layer 1, frame=1, Line 20Unexpected '}' encountered

                 

                And yes, the instance name on the button is toggleFullScreenButton.  Here is all the AS with your code that I just tried.

                 

                //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

                    // add a trace which appears in the output panel when you "TEST" your movie (e.g. CTRL+ENTER inside Flash)

                 

                     trace("Toggle full screen button was pressed");

                 

                 

                 

                     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);

                 

                 

                 

                And on the button itself is this code:

                 

                on(press){

                    toggleFullScreen();

                }

                • 5. Re: Fullscreen button in Actionscript 2
                  Cuwen Community Member

                  Well, I figured it out.  All I had to do was in Publish Settings under HTML click on 'Allow Flash'.  *facepalm here*  Thank you for the help.

                  • 6. Re: Fullscreen button in Actionscript 2
                    sinious MVP

                    Haha yes there's an extra brace after the function you pasted but I'm sure you found that.

                     

                    I thought you were running the SWF itself without HTML. Without HTML the SWF or a Projector with the code above would go fullscreen just fine

                     

                    Glad you got it working. Can you please mark this as solved.