4 Replies Latest reply on Aug 16, 2006 2:26 PM by cre8ive1974

    Resizing a box with AS

    cre8ive1974 Level 1


      I have a box graphic made in Flash on the screen. The size of the box is 100 pxls x 150 pxls.
      I also have 3 buttons on the screen. When the first button is pressed the box will resize to
      200 pxl x 300 pxls. When the second box is pressed it will resize to 50 pxls x 75 pxls and when
      the third button is pressed the box will resize to 175 pxls x 275 pxls. I would like to do this via AS
      and not have to animate the box in a MC. I would think that you would need to determine the size
      of the box before it resizes, becasue there is no way of knowing if the 1st, 2nd or 3rd button had
      been pressed previously.

      I have no idea where to begin with this.....Can anyone point me in the right direction?

      Thanks in advance!
      D
        • 1. Re: Resizing a box with AS
          Level 7
          cre8ive1974,

          > I would like to do this [resize a box graphic] via AS and
          > not have to animate the box in a MC. I would think that
          > you would need to determine the size of the box before
          > it resizes, becasue there is no way of knowing if the 1st,
          > 2nd or 3rd button had been pressed previously.

          If you're absolutely starting out, this can seem a bit complicated.

          > I have no idea where to begin with this.....Can anyone
          > point me in the right direction?

          I'll give it a shot. Your best bet, in my opinion, is to get a firm
          understanding of what objects are, and how they're used in ActionScript.
          Certain things (most things!) are accessible via ActionScript and certain
          things aren't. Graphic symbols are not accessible in ActionScript 1.0 or
          2.0, so you'll have to make your box a movie clip. Once you do that --
          bingo! -- you've got a world of functionality at your disposal. Why? Well,
          movie clip symbols are objects, which means you can manipulate them
          programmatically. Objects are defined by classes, and the ActionScript 2.0
          Language Reference is closely structured around these classes, so you won't
          even have to look far.

          If you're dealing with a movie clip, look up the MovieClip class in the
          ActionScript 2.0 Lanuage Reference. You'll find three categories:
          properties, methods, and events. Properties are the characteristics an
          object has, such as width and height; methods are the things an object can
          do, such as go to a frame and play; and events are things an object can
          react to, such as a mouse click. Not all objects have features in all three
          categories, but what they *do* have will be spelled out in the relevant
          summary in each class file.

          To resize a movie clip, you can, for example, set its _width and _height
          properties to whatever pixel size you like. How? You give your movie clip
          an instance name -- it is, after all, an instance of the MovieClip class --
          and then simply call it by name and tell it what to do. Because you're
          dealing with an instance, you specify the instance's name ...

          myClip

          ... and reference the desired class property ...

          myClip._width = 500;
          myClip._height = 300;

          etc.

          Doing so will immediately update the properties of your instance. If
          you want to resize your clip over time, you'll have to animate the property
          assignments. Animation, in this context, is simply change over time.

          You'll need a looping mechanism of some kind. Look to your MovieClip
          class entry, and you'll see an onEnterFrame event in the Events summary.
          This event is raised every time the movie clip enters a frame, which is
          roughly the rate of the movie's framerate (i.e., 12 times a second, by
          default).

          So you can assign a function to the event of your instance ...

          myClip.onEnterFrame = function() {
          this._width++;
          }

          ... which will increment the width of this clip by 1 twelve times a second.
          In this case, the word "this" refers to the instance named myClip, because
          "this" always points to the timeline or object it's in. Because it's scoped
          to the function assigned to the onEnterFrame event of myClip, it refers to
          myClip. The ++ operator is listed in the Language Reference under
          Operators. There are plenty of 'em.

          For fun, throw down a quick example in a new FLA and update a movie
          clip's _x property.

          These are the absolute basics, but it should at least get you started.
          Look through the "Learning ActionScript 2.0 in Flash" book in the
          documentation to learn about variables and other important terms you'll
          need.

          You may also get something out of this link, here, which explains
          objects in greater detail, illustrates how to get the most out of the
          ActionScript Language Referece, and explains how to debug your code.

          http://www.quip.net/blog/first-time-here/


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: Resizing a box with AS
            blemmo Level 1
            Make the box a MovieClip and give it an instance name, like 'box'. The buttons can then change the _width and _height properties of that MC:

            button1.onRelease = function(){
            box._width = 200;
            box._height = 300;
            }

            and similar for the other 2 buttons. This should be all.
            The box dimensions will be measured from it's registration point, so I guess you want to have this in the center of the box MC.

            hth,
            blemmo
            • 3. Re: Resizing a box with AS
              blemmo Level 1
              David was faster :)

              There seems to be some delay with the posts from the newsgroup, when I started answering there was no response, and it didn't take me 20 minutes to write...

              cheers,
              blemmo
              • 4. Re: Resizing a box with AS
                cre8ive1974 Level 1
                Thanks for the response!