// display object target, value - "center" or "upperLeft"
function setRegistration(dsp:DisplayObjectContainer, v:String):void {
var i:int;
var child:DisplayObject;
var b:Rectangle=getBounds(dsp);
for (i = 0; i < dsp.numChildren; i++) {
child=dsp.getChildAt(i);
child.x+=b.x*-1;
child.y+=b.y*-1;
}
if (v=="center") {
dsp.x+=dsp.width/2;
dsp.y+=dsp.height/2;
for (i = 0; i < dsp.numChildren; i++) {
child=dsp.getChildAt(i);
child.x-=dsp.width/2;
child.y-=dsp.height/2;
}
} else if (v == "upperLeft") {
if (dsp.parent) {
b=getBounds(dsp.parent);
dsp.x=b.left;
dsp.y=b.top;
}
}
}
// example:
// (make a MovieClip and fill it with, text, shapes etc...)
setRegistration(clip, "center");
// registration(clip, "upperLeft");
addEventListener(Event.ENTER_FRAME, onLoop);
function onLoop(evt:Event):void {
clip.rotation+=1;
}
Teaching beginner flash… I’ve noticed people always get confused about the registration point. They think they should be able to move it with the IDE or ActionScript. I always say “You can’t change the registration point, you can only change the position of graphical elements in relationship to it.” Anyway, as a sort of joke one day after class I wrote the above function… it changes the registration of any DisplayObjectContainer to either “center” or “upperLeft”.
To test this code out, fill a MovieClip with a bunch of different things (text, graphics, scribbles)… give it a strange registration point and then run the above code on it. You’ll be able to tell that the registration has changed by the way the clip rotates. Although I haven’t been able to break this function, I think it’s possible that it doesn’t work under all circumstances.
Using reparenting is a more elegant solution to this issue. Maybe I’ll post that in the next couple days.
Could provide this in as2.
can you upload a snippet for creating searchable xml database? i am searching it all over the internet ..but cant find a method that i can understand…i am a beginner . i’d really appreciate that.
thanks!