Monday, May 18, 2009

Registration Point Details(AS 3)

Registration Point is the (0,0) point of any display object . All the scaling , rotation etc take place with respect to this point . So its very much important to get a clear idea about registration point for any Action Script Developer. Sometimes when working with Action Script i faced several problems and recover them . Here i have tried to share my findings.

As i said earlier Registration point is the (0,0) point of any display object , so how to set it ? If the display object is not dynamically created then its a matter of dragging and dropping only. But if the display object is dynamically created then its a matter of calculation and planning.

Say you have to make a display object that is actually a rectangle that scales with respect to its center and you need it all dynamically . Here two points to be considered one Registration point is the point at (0,0) so to scale the object with respect to the center the rectangle should be drawn such way so the (0,0) point becomes the center of the rectangle so the display object scales or rotates around it .

But for complex display object or due to any other reason the Registration point may needed to be adjusted in many operations with many values . To do this only four steps are enough:
  1. get the value of the changed registration point with respect to the object where the display object under consideration is added .
  2. run the operation , rotate , scale
  3. get the value of the changed registration point with respect to the object where the display object under consideration is added after the operatoin .
  4. calculate the difference of the two points and minimize them in the x and y value of the display object
so a function like,

function doOperationRegChanged(op:String, val:Number,xreg:Number, yreg:Number):void {
var nrp:Point=new Point(xreg, yreg);
var bop:Point = this.parent.globalToLocal(this.localToGlobal(nrp));
this[op] = val;
var :Point = this.parent.globalToLocal(this.localToGlobal(nrp));
this.x -= b.x - a.x;
this.y -= b.y - a.y;
}
under a display object for which different registration point needed for different operation can be handled by calling
mc.doOperationRegChanged('scaleX',scaleX+1,-74,-22);
where mc is the display object.

For action script 3 i have found a blog from which i have found this idea , to know more about it click here .



Sound Sleep Really Helps!!!

I had a very busy Sunday and when i got back home at night i was having fever and headache . Somehow i managed to have shower and got my dinner and few sleeping pills . And i slept well, not a sound sleep though , i wont tell it sound sleep cause i was up in couple of occasions and in the morning when i was up finally nothing was changed , i was still having that bad headache so i called my office to grant me a day off and decided to sleep again. So i slept and this time when i woke up it was noon and i cant imagine how time ran that first!! Cause it seemed to me i just slept for 5 seconds and a bonus is that my headache was completely gone .

Being a webdeveloper and facing tough deadline sound sleep , to me, is a very rare thing !! But at least there are some times when i can have it and the most important part is after having that sort of sound sleep i felt very fresh to pass sometimes with blogs and cant resist to post something about the sound sleep .