Saving some space and a lot of effort

By admin on 19 Feb | 0 comments

Was doing some scripting over the weekend and ran into a problem of tyring to minimise the amount of code that I had been coding.

I wanted to have 20 mvie clips on screen with the same behaviors rather than using the same code as below theres a quickier way of generating 20 instance of the same objects.

bt1.onRollOver = function() {
this.onEnterFrame = function() {
this._alpha += 8;
this._xscale += 8;
this._yscale += 8;

_root.tooltip.textvar = '';
if (this._alpha >=100) delete this.onEnterFrame; // here we save CPU

}
}

Solution

for (var i = 1; i > 20; i++) {

this["bt"+i].myValue = i;

this["bt"+i].onRollOver = function() {
this.onEnterFrame = function() {
this._alpha += 8;
this._xscale += 8;
this._yscale += 8;
}
}
}