View Full Version : (AS3) set MovieClip registration
pi3rc3
12-27-2006, 06:50 PM
anyone know of a way to use actionscript3 to set the registration point of a MovieClip?
TheCanadian
12-27-2006, 07:04 PM
The registration point is always (0, 0), so you'll have to draw your content around that.
Dazzer
12-27-2006, 09:57 PM
but it might just be possible to simulate it with matrix transforms.
just maybe.
do let us know if you figure something out kudos!
stringy
12-28-2006, 09:15 AM
Just go to the library,edit it in place and move it. Same as ever.
if you are creating dynamically(for whatever reason) do as TC says-
Detrus
07-15-2007, 02:50 PM
http://www.oscartrelles.com/archives/dynamic_movieclip_registration_with_as3
workaround feels weird, can't figure how to add it to various masks from library, then to new DynamicMovie, then to array, but may as well set library items up manually.
CarlLooper
07-15-2007, 05:55 PM
The "registration point" of a MovieClip is it's "negative" position relative to it's container.
For example, if you wanted your registration point to be 10 pixels down and 10 pixels right from top left corner of clip then you would set the clip's x,y as (-10,-10)
Apply masking to the container.
Move the clip around by moving it's container around (ie. not the clip)
Rotate the clip around by rotating either the clip (mask stays put) or it's container (mask rotates with clip).
Carl
Detrus
07-15-2007, 11:07 PM
right, i wanted to use this dynamic registration class though. I could put Sprites into Sprites to fake a registration point, but then I'll want to do weird calculations and it will become a hassle adjusting containers' x,y positions.
i'm working with this code after i load an image, curLD is what's currently Loading.
function loaded(event:Event):void
{
var contents:Bitmap = event.target.content;
var myBitmapData:BitmapData = new BitmapData(contents.width, contents.height);
myBitmapData.draw(contents);
var bmp:Bitmap = new Bitmap(myBitmapData, "auto", true)
Pic[curLD] = new DynamicMovie()
Pic[curLD].setRegistration(bmp.width/2, bmp.height/2);
maskos[curLD] = new masky()
//maskos[curLD].x = bmp.width/2
//maskos[curLD].y = bmp.height/2
Pic[curLD].mask = maskos[curLD]
Pic[curLD].addChild(maskos[curLD])
Pic[curLD].addChild(bmp)
addChild(Pic[curLD])
Pic[curLD].x2 = 140*curLD - 1500
Pic[curLD].y2 = 18*curLD
curLD++
//etc..
}
not sure how to add the mask sprite to the new DynamicMovie(), i can hackily duplicate the class, and stick my shape into the symbol in the library of course. Just very confused by this AS3 attaching.
CarlLooper
07-16-2007, 01:33 AM
Yes, it can be a bit of nightmare, I agree, but if you invent some rules for yourself, it can become a little bit more manageable.
The basic idea is to treat your container as the main object. But don't do anything with the container. Add children to it. Let the children implement all the display stuff. You can adjust the children up and down relative to the container. The container itself is empty, but it nevertheless represents your main object.
When you subsequently go to recompose the object (eg. attaching it to another object) you just use the container. It is your main object - one you can translate and rotate.
If you need to mask the object - create a new parent object, and add all your container objects (to be masked) to that parent.
ie. start at the bottom of the display list (building each container separately) and compose your way up to the top of the display list. Like building the pyramids, from the ground up. Your very last stone is added to the sky (the stage or root display object) - at which point your pyramid becomes visible.
Carl
cayennecode
09-18-2007, 03:44 PM
I'm just thinking this one up on the spot, but I think this would be a nice center registration implementation
public class GUI extends Sprite
{
private var container:Sprite;
public function GUI()
{
addChild(container = new sprite());
}
public override function addChild(dObj:DisplayObject, coords:Object):void
{
dObj.x = coords.x;
dObj.y = coords.y;
container.addChild(dObj);
updateRegPoint();
}
private function updateRegPoint():void
{
container.x = -container.width>>1;
container.y = -container.width>>1;
}
}
Instance usage
var gui:GUI = new GUI();
gui.addChild(someChild, {x:30, y:40});
gui.addChild(anotherChild, {x:400, y:30});
gui.addChild(babySitter, {x:6, y:9});
you like? You could abstract this one, and extend it, or something. Although I've never tried to override the addChild method, I think it should work.
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.