Dynamic MovieClip Registration with AS3
So, you wanna change the registration point of a MovieClip at runtime? Here is some piece of code that allows you to do just that.
Based on an old AS2 class written by Darron Schall, this AS3 class extends MovieClip and adds a new set of properties (x2, y2, rotation2, scaleX2, scaleY2, mouseX2, mouseY2) that allow you to manipulate the sprite based on a contextual registration point that can be set using the setRegistration method.
Here is how it works:
1 2 3 4 5 6 7 8 9 10 11 | // Create a new instance var square:DynamicMovieClip = new DynamicMovieClip(); addChild(square); // Change registration coordinates at runtime square.setRegistration(20, 20); // From this point on, instead of using 'rotation' // we use 'rotation2' // Same principle applies for 'x', 'y', 'scaleX' and 'scaleY' square.rotation2 = 45; |
Here’s a simple application.
Comments (25)
Daniel
July 13th, 2010 at 5:40 am
hi!
where is the source file?
i don’t see it there anymore.
Please put it up, thanks!
Oscar Trelles
July 17th, 2010 at 12:37 pm
Thanks for the heads up. Some things were out of place after migrating the site to WordPress. Everything should be back to normal now.
jookyone
August 9th, 2010 at 12:54 pm
Great class… saved me loads of time trying to play with the math.
Chris
August 11th, 2010 at 1:35 am
Great script!
I have tried for so long to get my own scripts working (and ones from other sites). Using a mix of matrix’s etc, and none worked, esp. with Tween classes.
This one does work!
Thanks
tsk
August 11th, 2010 at 9:32 am
This is just A-M-A-Z-I-N-G man. Works perfect. Thank you very much!
Greets.
tsk
Cuagain
August 24th, 2010 at 6:14 am
Thanks for a good code.
I downloaded and used it but does not work.
It wrong at constructor name of DynamicMovie class which in code is DynamicSprite.
I change it to DynamicMovie and work fine.
Mirko
September 6th, 2010 at 11:08 am
Awesome, thank you very much!
Keith
September 22nd, 2010 at 9:26 am
Thanks a lot!!
tony
September 25th, 2010 at 8:19 am
where is the code for the DynamicMovieClip() class?
John
October 14th, 2010 at 4:24 pm
I still don’t see the source code for this class. It would be very helpful.
registrierungs punk zur laufzeit
October 28th, 2010 at 9:26 am
[...] [...]
adishaswot
October 29th, 2010 at 7:10 am
The Example is awesome. This just Opened Up a concept for game development!
Thanku~!!!
Alex
December 7th, 2010 at 11:10 pm
Thank you so much, I am a flash developer my self and I have been working on something like this, I was unable to figure it out though. This will be enormously helpfull! Thank you sooooo much
Wilson Silva
January 13th, 2011 at 2:08 am
Thank you! I’m amazed by this piece of code.
Dingfeng
January 18th, 2011 at 5:57 pm
It can work normally,think you very much!
Shaffe
February 4th, 2011 at 12:57 am
Congrats, it’s working great!
Brian
February 9th, 2011 at 5:28 pm
That’s a smart bit of code. Thanks!
michelle
February 10th, 2011 at 2:45 pm
Can this be applied to a png Bitmap?
Niklas B
March 30th, 2011 at 5:29 am
Awesome!
michelle: I put the bitmap data into the DynamicMovie which works fine,
var mc:DynamicMovie = new DynamicMovie();
mc.addChild( bitmap as DisplayObject );
Worth mentioning (if not only just for Google). You need to add the new DynamicMovie to any MC before using rotation2 or any of the other values. Otherwise you will get a:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at DynamicMovie/setProperty2()
at DynamicMovie/set rotation2()
aris
June 23rd, 2011 at 12:45 am
can you help me how to set up the regristration of MC in flash lite? please
nasim
July 25th, 2011 at 12:35 am
Hi
Where is The source code?
nasim
July 25th, 2011 at 2:28 am
sorry I get it
I have big problem when i draw graph with loop and graphics.lineTo method I want to palce it finally in special place with special scale , But it cant work and start x,y from 0,0 i have diferent graphs and i can’t set the place manually Could u help me
Josh
July 28th, 2011 at 4:50 pm
How would you change this code to a MouseDown Event??
stage.addEventListener(KeyboardEvent.KEY_DOWN, changeRotation);
function changeRotation(event:KeyboardEvent):void
{
if(event.keyCodegt;36 amp;amp; event.keyCodelt;40)
sq.rotation2 -= 38 – event.keyCode;
}
nasim
August 1st, 2011 at 6:29 pm
Hi
Could u help me . i draw wave( by code) inside empy movieClip that se regpoint (manualy) at middle of that when i scale it t it’s good but when i move align x or y I want to change reg point and refrence point too , like when i do it manualy , the refrence point means (0,0) point , how do i change that point plese help me
Singe Volant
December 23rd, 2011 at 6:51 pm
Thanks!! This is awesome, you just saved me a severe headache!
Leave a reply