PDA

View Full Version : scale out from center



sweepah
April 23rd, 2003, 05:51 AM
I actually spend some time searching how it could be done, its quite simple but maybe it will be some use for someone and since I have been lurking around for a while it seemed like a good way to say hi:P. It makes up for the fact that flash scales from the registration point.

MovieClip.prototype.centreScale = function(speed) {
this._x += this._width/2;
this._y += this._height/2;
// get the necessary properties
var steps = 100/speed;
var xrate = this._width/2/steps;
var yrate = this._height/2/steps;
// scale to 0
this._xscale = 0;
this._yscale = 0;
if (this._xscale<100) {
// scale out
this.onEnterFrame = function() {
if (this._xscale<100) {
with (this) {
_xscale += speed;
_x -= xrate;
_yscale += speed;
_y -= yrate;
}
}
};
} else {
delete this.onEnterFrame;
}
};

Usage:

_root.onLoad = function() {
// draw your object
object.centreScale(2);
}