Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Flash Actionscript / August 2006



Tip: Looking for answers? Try searching our database.

Rotating Picture in Place

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cmalumphy - 31 Aug 2006 02:19 GMT
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.