6 Replies Latest reply: Sep 3, 2007 10:55 AM by Newsgroup_User RSS

    change stage width in AS3

    Flamebg Community Member
      Ok so In AS2 I could change the Stage width with code like this:

      Stage.width = 1000; (usually to match different resolutions for certain projects I used some code here to get current resolution of screen and make the stage same width minus a few more pixels cuz of the scroolbar)

      Now.. I see that i must type a code like this:
      stage.stageWidth = 1000;

      The problem is that this value is not writable no matter it says so in the flash help. So I can't change it :(

      Can anyone tell me how I can change the stage width using AS3 please ?

      Flame
        • 1. Re: change stage width in AS3
          Newsgroup_User Community Member
          Flamebg,

          > Ok so In AS2 I could change the Stage width ...

          Huh?

          > ... with code like this:
          >
          > Stage.width = 1000; (usually to match different resolutions
          > for certain projects I used some code here to get current
          > resolution of screen and make the stage same width minus
          > a few more pixels cuz of the scroolbar)

          Oh wow. Actually, the Stage.width and Stage.height properties are
          read-only. They do not (cannot) affect the width of the Stage, but only
          report on what its current dimensions are. If you want a resizable Stage,
          you have to toy with the Stage.scaleMode property. You can set the Stage
          (the SWF itself) to resize itself in ways that respect and ignore aspect
          ratio, and you can even choose "noScale" but override that in your HTML by
          using 100% for the width and height attributes of your OBJECT and EMBED
          tags. Going this last route affords you the opporunity to respond to
          changes in Stage dimension by assigning a function to the Stage.onResize
          event.

          http://www.quip.net/blog/2006/flash/how-to-position-movie-clips-browser-resizing

          > Now.. I see that i must type a code like this:
          > stage.stageWidth = 1000;

          Those properties are still read-only, even in ActionScript 3.0.

          > The problem is that this value is not writable no matter it says so in the
          > flash help. So I can't change it :(

          The Flash Help states that the stageWidth and stageHeight properties are
          non-writable, which is true. ;) In AS3, the resize event is your
          equivalent to the onReisze event of AS2.

          > Can anyone tell me how I can change the stage width using AS3 please ?

          You can't change it, in either version of ActionScript. You can only
          respond to it. Responding requires that the Stage's scale mode is set to
          "no scale" -- following the case and spelling conventions pertinent to the
          chosen version of the language -- and then setting its width and height to
          some percentage in HTML. Then handling the onResize / resize event. In
          AS3, the event handler might look like this:

          stage.scaleMode = StageScaleMode.NO_SCALE;
          stage.align = StageAlign.TOP_LEFT;
          stage.addEventListener(Event.RESIZE, resizeHandler);

          function resizeHandler(evt:Event):void {
          // instructions here (elements to stretch, resposition, etc.)
          }


          David Stiller
          Co-author, Foundation Flash CS3 for Designers
          http://tinyurl.com/2k29mj
          "Luck is the residue of good design."


          • 2. Re: change stage width in AS3
            richtextformat Community Member
            you might find the answer here:

            http://tinyurl.com/3777uo

            :)
            • 3. Re: change stage width in AS3
              Flamebg Community Member
              thank u david :]
              I will try this out now !
              btw.. u are not right about Stage.width not working with AS2, I did that 2 or 3 times and it does work (u can see that even on the preview).

              Try it out if u want :)
              If I got more questions I will post again ;]

              thanks a lot
              • 4. Re: change stage width in AS3
                Newsgroup_User Community Member
                Flamebg,

                > thank u david :]
                > I will try this out now !

                Sure thing. :)

                > btw.. u are not right about Stage.width not working with AS2,
                > I did that 2 or 3 times and it does work (u can see that even
                > on the preview).

                I didn't say Stage.width doesn't work. ;) Certainly it works! It's a
                read-only property that reports on the width of the Stage. It just can't be
                used to *set* the width of the Stage.

                > Try it out if u want :)

                I created a FLA file 200 pixels wide and pasted in the following code:

                trace(Stage.width);
                // outputs 200, as expected

                Stage.width = 800;
                trace(Stage.width);
                // still outputs 200, because Stage.width can't be set

                box._x = Stage.width;
                trace(box._x);
                // moves a movie clip with the instance name "box" to
                // the visible edge of the Stage and outputs 200

                It may be that I didn't understand your description earlier. Let me
                know if I didn't get what you were saying.


                David Stiller
                Co-author, Foundation Flash CS3 for Designers
                http://tinyurl.com/2k29mj
                "Luck is the residue of good design."


                • 5. Re: change stage width in AS3
                  Flamebg Community Member
                  Well you kinda missunderstood, I meant that in AS2 u can set the width property but LOL :D now I checked it and u are actually right again.. u really can't.
                  What I actually did with AS2 was to put Stage width at about 1500 px noscale which will most of the times be more than the screen resolution, so when u put the flash in html and u resize the window with left flash alignment and change the resolution from 1024x768 to 1280x... you still see the flash like it is resizable.
                  But after what you said now I begin to understand that I could just set set my stage width and height to 100% with noscale mode again.. and have the same effect, even better ;]

                  correct me if I am wrong ;)

                  thanks a lot for the advice, I will write again if I got more questions ;]
                  • 6. Re: change stage width in AS3
                    Newsgroup_User Community Member
                    Flamebg,

                    > after what you said now I begin to understand that I could
                    > just set set my stage width and height to 100% with noscale
                    > mode again.. and have the same effect, even better ;]

                    You got it. That's the way to go. :) Taking the route of
                    Stage.onResize (AS2) or stage.resize (AS3) means you don't have to guess at
                    peoples' monitor resolutions.


                    David Stiller
                    Contributor, How to Cheat in Flash CS3
                    http://tinyurl.com/2cp6na
                    "Luck is the residue of good design."