2 Replies Latest reply on Jun 4, 2007 6:19 AM by Newsgroup_User

    Rotate a dynamilly created movie clip?

    Level 7
      I need to rotate this[PhotoMovieName]. But the registration point is the
      upper left corner. I want them to rotate on center.
      Is there a way to do this. Can I change the registration point with AS?

      PhotoArray = new Array("1.jpg","2.jpg","3.jpg","4.jpg","5.jpg");
      //trace(PhotoArray.length);
      for(i=0;i<PhotoArray.length;i++){
      trace(PhotoArray );
      PhotoMovieName = "Photo"+i;
      var container:MovieClip = this.createEmptyMovieClip(PhotoMovieName,
      this.getNextHighestDepth());
      this[PhotoMovieName].loadMovie("Photo.swf");
      //this[PhotoMovieName].Photo_ldr._x=0;
      //this[PhotoMovieName].Photo_ldr._y=-50;
      this[PhotoMovieName]._rotation = 15*i;
      this[PhotoMovieName]._y = 200;
      this[PhotoMovieName]._x = 200;

      //this[PhotoMovieName].contentPath = PhotoArray
      ;
      //this[PhotoMovieName].Photo_ldr.load();
      //trace(this[PhotoMovieName]._x+"----"+this[PhotoMovieName]._y);
      }\
      \


      Thanks,

      Jason


        • 1. Re: Rotate a dynamilly created movie clip?
          Level 7
          Jason,

          >I need to rotate this[PhotoMovieName]. But the registration point
          > is the upper left corner. I want them to rotate on center. Is there a
          > way to do this. Can I change the registration point with AS?

          ActionScript doesn't let you change an asset's registration point, but
          the workaround is pretty easy. In your case (ActionScript 1.0/2.0) you'll
          create a containing clip first, then create another inside it -- as you're
          doing -- then offset the inner clip's midpoint to meet the registration
          point of the container.

          var container:MovieClip = this.createEmptyMovieClip(
          PhotoMovieName, this.getNextHighestDepth()
          );

          So far, so good, right? Nothing has chnaged yet. Now, because you've
          created the variable container, and because the
          MovieClip.createEmptyMovieClip() method returns a reference to the newly
          created clip, may use the container variable in place of
          this[PhotoMovieName] -- because the reference to that clip is stored in
          container.

          container.loadMovie("Photo.swf");

          Again, that's functionally identical to the earlier version,
          this[PhotoMovieName].loadMovie("Photo.swf"); ... now, the important part at
          this point is to *wait* until Photo.swf has loaded. Until it does, you
          can't really continue, as you've done, with rotation, x, and y settings. If
          you go the route of loadMovie(), you basically have to set up a loop
          (setInterval(), say, or onEnterFrame) and repeatedly check the
          MovieClip.bytesLoaded() and bytesTotal() methods of your container clip
          until the loaded bytes meet the total. Here's some detail on that process
          ...

          http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded/

          ... Finally, you'll want to bump the loaded left by half its width and up by
          half its height -- then move the container to compensate. So, how do
          reference the loaded clip inside the container? Aha! Well, once Photo.swf
          is loaded, it's container effectively *is* the loaded asset. You'll need
          two containers, then. An outer and an inner.

          var outer:MovieClip = this.createEmptyMovieClip(
          PhotoMovieName, this.getNextHighestDepth();
          );
          var inner:MovieClip = outer.createEmptyMovieClip("mcInner", 0);

          inner.loadMovie("Photo.swf");

          outer.onEnterFrame = function():Void {
          if (inner.getBytesLoaded() >= inner.getBytesTotal()) {
          inner._x -= inner._width / 2;
          inner._y -= inner._width / 2;
          this._x += inner._width / 2;
          this._y += inner._width / 2;
          this._rotation = 45;
          delete this.onEnterFrame;
          }
          }

          A couple key things to note: again, the variable outer refers to
          whatever string is contained by the PhotoMovieName variable. This time,
          there's also an inner clip inside that one. The inner clip is basically
          taking the place of your original container. Once loading starts, a loop
          checks the loading SWF, as described in that blog link, and when the SWF has
          finished, inner is offset left and up, outer is offset right and down, and
          finally outer is rotated.


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


          • 2. Re: Rotate a dynamilly created movie clip?
            kglad Adobe Community Professional & MVP
            you can't change the registration point with actionscript but you can make it appear the reg point has been changed.

            the code above the dotted line will add several properties to your movieclips which allow you to specify the location of an apparent registration point and then manipulate the movieclip as if the reg point has changed.

            an example, applying some of these new properties is below the dotted line: