2 Replies Latest reply on Aug 31, 2006 2:14 AM by cmalumphy

    Rotating Picture in Place

      I want to load a gif file into a movieclip and rotate it around its center point. But my code rotates the picture around the 0,0 point in the top right corner.

      var cx:Number = Stage.width / 2;
      var cy:Number = Stage.height / 2;

      import flash.display.BitmapData;

      //my picture 506px by 366 px
      var pic:BitmapData = BitmapData.loadBitmap("meany");

      //create movieclip
      this.createEmptyMovieClip("mypic", this.getNextHighestDepth());

      //put bitmap into movieclip
      mypic.attachBitmap(pic, this.getNextHighestDepth());

      //create main movieclip and place myclip into it, hopefully offsetting it so it is centered
      this.createEmptyMovieClip("meany",this.getNextHighestDepth(), {_x: -253, _y: -183});
      meany.attachMovie(mypic, "mypic", this.getNextHighestDepth(), {_x: -253, _y: -183});

      meany.mypic._rotation = 180;
      meany.mypic._x = cx;
      meany.mypic._y = cy;

      function onEnterFrame() {
      mypic._rotation += 5;
        • 1. Rotating Picture in Place
          Craig Grummitt Level 3
          the code attached will create an empty holder movie clip(holder_mc) and place this in the middle of the screen based on stage width and height. it then creates an empty movieclip(mc) inside this, and attaches a bitmap from the library with a linkage identifier of "meany" to this. it then places this mc in the centre by subtracting half of the width and height of the bitmap. now it rotates the bitmap in the centre onEnterFrame.

          a couple of comments on your code:

          createEmptyMovieClip doesn't accept an initobject (eg {_x: -253, _y: -183}) good thing - you were doubling up on this anyway.
          attachMovie only attaches clips from the library - also the parameter you are passing in this line(mypic) is a movieclip and not a string which is what flash is expecting.
          • 2. Re: Rotating Picture in Place
            cmalumphy Level 1
            Thanks very much. Your code works beautifully. Obviously I have much to learn. Thanks for the tips.