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;
}
Craig Grummitt - 31 Aug 2006 04:56 GMT
this code 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.
import flash.display.BitmapData;
var pic:BitmapData = BitmapData.loadBitmap("meany");
this.createEmptyMovieClip("holderMC", 1);
this.holderMC._x = Stage.width/2;;
this.holderMC._y = Stage.height/2;
this.holderMC.createEmptyMovieClip("mc", 1);
this.holderMC.mc._x = -pic.width/2;
this.holderMC.mc._y = -pic.height/2;
this.holderMC.mc.attachBitmap(pic, this.getNextHighestDepth());
this.holderMC.onEnterFrame = function() {
this._rotation += 5;
};
cmalumphy - 31 Aug 2006 10:14 GMT
Thanks very much. Your code works beautifully. Obviously I have much to learn. Thanks for the tips.