2 Replies Latest reply on May 6, 2006 8:08 AM by Newsgroup_User

    How to Expand a Movie Clip

    Level 7
      Hi,

      I want to expand a MC (talking about the size) from the middle.
      To be more clear.
      I have a mc with these properties
      _width : 100
      _height : 100
      _x = 50
      _y = 50

      I want when I use a rollover function, to change its properties like this :

      _width : 200
      _height : 200
      _x = 50
      _y = 50

      The _x and _y have the same values just want to change the _width and
      _height.
      And of course, I would like to the tween effect.

      How to do this with actionscript ?

      Thanks in advance.
      Stan


        • 1. Re: How to Expand a Movie Clip
          Level 7
          Attach this to a frame with the clip in it:

          var startScale = 100;
          var endScale = 200;
          var speed = 10;
          //
          myClip.onRollOver = function () {
          this.onEnterFrame = function () {
          if (this._xscale < endScale) {
          this._xscale += speed;
          this._yscale += speed;
          } else {
          this._xscale = endScale;
          this._yscale = endScale;
          delete this.onEnterFrame;
          }
          };
          };
          myClip.onRollOut = function () {
          this.onEnterFrame = function () {
          if (this._xscale > startScale) {
          this._xscale -= speed;
          this._yscale -= speed;
          } else {
          this._xscale = startScale;
          this._yscale = startScale;
          delete this.onEnterFrame;
          }
          };
          };


          Also, to have it expand from center, and not upper-left make sure you go
          into the clip and adjust it - if the width is 100 the shape within the clip
          should start at x: -50, not 0...same with y.

          --
          Dave -
          Adobe Community Expert
          www.blurredistinction.com
          www.macromedia.com/support/forums/team_macromedia/


          • 2. Re: How to Expand a Movie Clip
            Level 7
            Hi Dave,

            I ve tried your bit of code, it seems that it works.. but, as you ve
            mentionned if I want to expand from the center I have to set -50 to _x and
            _y..
            In fact, I don't know how to do it.
            Here's my code. (it's not pure :-) I m a newbie).

            import flash.filters.ColorMatrixFilter;
            import mx.transitions.Tween;
            import mx.transitions.easing.*;
            System.security.allowDomain("mydomain");

            var startScale = 100;
            var endScale = 200;
            var speed = 10;

            this.createEmptyMovieClip("my_mc",10);
            my_mc.createEmptyMovieClip("container_mc",99);
            var mcl_obj bject = new Object();
            mcl_obj.onLoadInit=function(target_mc:MovieClip):Void{
            target_mc._height=86;
            target_mc._width=115;
            target_mc._x=100;
            target_mc._y=100;
            var myElements_array:Array=[0.3,0.59,0.11,0,0,
            0.3,0.59,0.11,0,0,
            0.3,0.59,0.11,0,0,
            0,0,0,1,0 ];
            var myColorMatrix_filter:ColorMatrixFilter=new
            ColorMatrixFilter(myElements_array);
            target_mc.filters=[myColorMatrix_filter];
            target_mc.onRollOver=function(){
            this.filters=undefined;
            this.onEnterFrame = function () {
            if (this._xscale < endScale) {
            this._xscale += speed;
            this._yscale += speed;
            } else {
            this._xscale = endScale;
            this._yscale = endScale;
            delete this.onEnterFrame;
            }
            };
            }
            target_mc.onRollOut=function(){
            this.filters=[myColorMatrix_filter];
            this.onEnterFrame = function () {
            if (this._xscale > startScale) {
            this._xscale -= speed;
            this._yscale -= speed;
            } else {
            this._xscale = startScale;
            this._yscale = startScale;
            delete this.onEnterFrame;
            }
            };

            }



            }

            var my_mcl:MovieClipLoader = new MovieClipLoader();
            my_mcl.addListener(mcl_obj)
            my_mcl.loadClip("mydomain/image.jpg");


            PS :
            The image that I load from the loadClip has a size 640x400 pixels.
            That's the reason I resize it to 115x86
            My need is :
            Display the image with a size of 67x50 Pixels and when the rollover is
            active expand it (from the center) to 115x86.

            Any help ??

            Stan