[FMX] Processor Usage Optimization

Yo. I have a script as follows attached to an MC that is pretty processor intensive (well, that is when the MC is duplicated 30 times). I’m looking for some input from people on how to possibly optimize this to cut back on how badly it lags the rest of the movie. My computer is quite powerful but it still shows performance issues with this script:

[AS]
onClipEvent(load) {
//size of purpleCloud’s active area
movieWidth = 700;
movieHeight = 175;

//cloud's dimensions (randomly changed)
	//y scale between 15 and 60
	this._yscale = 15 + Math.random() * 45;
	//x scale between 50 and 130
	this._xscale = 50 + Math.random() * 80;
	
//cloud's transparency
	//between 10 and 40
	this._alpha = 10 + Math.random() * 30;

//cloud's initial position
	this._x = Math.random() * movieWidth;
	this._y = Math.random() * movieHeight;

}

onClipEvent(enterFrame) {
//section to regulate cloud position

	//cloudSpeed dependent on mouse and alpha.  Combined <= 1
	cloudSpeed = ((_root._xmouse) - 350) * .0028 * (this._alpha * .025);
	
	this._x += cloudSpeed;
	
//if cloud goes outside movie clip, place it back at beginning
	if ((this._x - this._xscale) >= movieWidth) {
			this._x = - this._xscale;
	}
	if ((this._x + this._xscale) <= 0) {
			this._x = movieWidth + this._xscale;
	}

}
[/AS]

Any help is greatly appreciated. Again as I mentioned, the clip that contains this MC has the movie duplicated 30 times, creating the major drain. Other than cutting this number back, any suggestions on optimizing it? Thx

John

I haven’t done much optimization in Flash, but I’ll give you a few thoughts anyway…

In the line
[AS]
cloudSpeed = ((_root._xmouse) - 350) * .0028 * (this._alpha * .025);
[/AS]

you could multiply this._alpha by 0.00007 instead of first multiplying it by 0.025 and then by 0.0028.

(_root._xmouse - 350) is also a calculation you do for all 30 mc’s and it’s the same in all of them. You could calculate it once and use it in all the mc’s. I don’t know where to put such a calculation, but maybe you do.

I think that what’s slowing you down is really the fact that you have 30 clips and generate a lot of overhead in Flash. Have you tried keeping the clouds in an array and drawing them in the same mc? I don’t know if it’ll in fact help or if it’s possible in your case, but maybe you can give it a shot.

Anyway, I’d like to hear what you come up with. We can all use faster code, I think…

yeah, alpha stuff is always a b*tch wtih flash.

I decided the mouse related effect wasn’t relevant enough to keep. Would it be better to make the speed random than to have it alpha dependent? Or are they about the same (regarding processor usage)?

j