PDA

View Full Version : Problem with prototype



El Bicho
April 18th, 2004, 08:12 PM
I have this code. The clip moves in a slow spiral trajectory until it stops. When I increase the number of clips (var totalClips) the behaviour changes. The movement is faster and they make more "laps" until they stop.
Any hint?
Thanks.



MovieClip.prototype.move = function(x, y, radio) {
this.radio = radio;
this.onEnterFrame = function() {
if (this.radio>=0) {
this.radio -= 2;
this._x = x+this.radio*Math.cos(t*Math.PI/180);
this._y = y+this.radio*Math.sin(t*Math.PI/180);
t += 10;
}
};
delete this.onEnterFrame();
};
totalClips = 1;
for (i=1; i<totalClips+1; i++) {
attachMovie("circle", "circle"+i, i);
}
for (a=1; a<totalClips+1; a++) {
eval("circle"+a).move(150, a*50, 150);
}

kode
April 18th, 2004, 09:01 PM
Define the variable "t" as a local variable:

MovieClip.prototype.move = function(x, y, radio) {
var t = 0;
this.radio = radio;
this.onEnterFrame = function() {
if (this.radio>=0) {
this.radio -= 2;
this._x = x+this.radio*Math.cos(t*Math.PI/180);
this._y = y+this.radio*Math.sin(t*Math.PI/180);
t += 10;
}
};
delete this.onEnterFrame();
};
Or define it in the movie clip itself:

MovieClip.prototype.move = function(x, y, radio) {
this.t = 0;
this.radio = radio;
this.onEnterFrame = function() {
if (this.radio>=0) {
this.radio -= 2;
this._x = x+this.radio*Math.cos(this.t*Math.PI/180);
this._y = y+this.radio*Math.sin(this.t*Math.PI/180);
this.t += 10;
}
};
delete this.onEnterFrame();
};