3 Replies Latest reply on Mar 15, 2007 7:42 AM by Dave.Hollings

    ActionScript help - MovieClip

    Dave.Hollings Level 1
      Hi all,

      I was hoping someone will be able to help, I have an mc which is basically a filled rectangle which a width of 1px. I need to work out the actionscript to make the bar get wider by so many pixels as the timeline processes on another mc. This is a little like a loading progress bar however I do not need it to load content I what to give the user the appearance of lead-time. The main mc is showing where shipments come from around the work via land, sea and air. As this happens I need the action script to move the lead-time progress bar from week 6 to week 0 a total pixel width of 550.

      Any help would be very much appreciated.
        • 1. Re: ActionScript help - MovieClip
          Level 7

          > I have an mc which is basically a filled rectangle which
          > a width of 1px. I need to work out the actionscript to
          > make the bar get wider by so many pixels as the
          > timeline processes on another mc.

          The trick to this sort of animation -- to any sort of animation -- is to
          adjust a visual element (here, width) over time. You're dealing with a
          movie clip, so your best bet is to consult the ActionScript 2.0 Language
          Reference's entry on the "MovieClip class." Think of a class as a blue
          print: it defines a particular kind of object, stating what it's
          characteristics are (properties), the things it can do (methods), and the
          things it can react to (events).

          Among the properties, you'll find a _width property. You'll need to
          give your movie clip an instance name (see the Property inspector while that
          clip is selected) -- that allows you to reference MovieClip class members on
          that *particular* MovieClip instance. So width is covered; now we need to
          discover how the "over time" part goes.

          In the MovieClip class, you'll see an onEnterFrame event, which is
          dispatched in synchrony with your movie's framerate. You'll assign a
          function to that event, then tell that function what to do.

          myClip.onEnterFrame = function():Void {
          this._width = ??;

          This code would go in a timeline frame, and this is why instance names
          are important. If the code is in a frame, it needs to know what object(s)
          it's talking to.

          If you want to increment width, you could use the ++ operator, which
          adds 1 to a value, or the += operator, which allows you to specify. For
          example ...

          myClip.onEnterFrame = function():Void {
          this._width += 4;

          ... would increase myClip's width by 4 pixels every time the movie enters a
          frame (this occurs even when the playhead is stopped). In a sense, it makes
          no difference which clip you use to generate the enterframe ticking. It's
          based on the movie's framerate, which doesn't change. Use logical operators
          to determine when to change or stop (search "operators" in the documentation
          to see all your choices).

          myClip.onEnterFrame = function():Void {
          if (this._width < 500) {
          this._width += 4;
          } else {
          delete this.onEnterFrame;

          In this last sample, myClip's width is checked against an arbitrary
          figure, 500, to see if it's still smaller than that. If it's smaller, it
          increments myClip's width by 4; otherwise, it kills the onEnterFrame event
          handler (the function).

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

          • 2. Re: ActionScript help - MovieClip
            mclem Level 1
            you could make the bars width 550 and then bassed on the mc._currentframe / mc._totalframes move a mask from left to right so if the mc was at frame 50 of 100 then the mask (which would be the same length as the bar aka 550pixels) would be moved over 275 pixels from it's original position.

            the only other thing to do is add a background bar that is not masked that shows the total length of the progress bar all 550 pixels long.
            • 3. Re: ActionScript help - MovieClip
              Dave.Hollings Level 1

              Many thanks for both the information and your help, not only have you provide a solution you have explained everything extremely well. I nice to see that people on this forum still have the time and patience’s for one another its a great community of experience. I was aware that there were _width property however was unsure how to actually write the code to implement what I desired. Once again many thanks.

              mclem - you provide another nice alternative however after reviewing David’s reply and applying this method it works so well haven’t used the mask idea. However saying that I did thing the masking would be the way to go. Thank you for your comments they were not left un-noticed.