//------------------------------------------------------------
//----------------------[ Frame One ]-------------------------
//------------------------------------------------------------
MovieClip.prototype.Cross = function(x, y, size, width, stroke, fill) {
width = width/2;
this.lineStyle(stroke.width, stroke.color, stroke.alpha);
this.beginFill(fill.color, fill.alpha);
this.moveTo(-width-size, width);
this.lineTo(-width, width); // -h so the registration point is in the right place, h would turn it upside down.
this.lineTo(-width, size+width);
this.lineTo(width, size+width);
this.lineTo(width, width);
this.lineTo(width+size, width);
this.lineTo(width+size, -width);
this.lineTo(width, -width);
this.lineTo(width, -width-size);
this.lineTo(-width, -width-size);
this.lineTo(-width, -width);
this.lineTo(-width-size, -width);
this.endFill();
this._x = x;
this._y = y;
}
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.round(Math.random()*(max-min))+min;
return randomNum;
}
function trig(x1, x2, y1, y2) {
xdist = x2 - x1;
ydist = y2 - y1;
xdist = xdist*xdist;
ydist = ydist*ydist;
dist = xdist+ydist;
var dist = Math.sqrt(dist);
return(dist);
}
MovieClip.prototype.fly2Point = function(x, y, speed, initwidth, initheight, initx, inity) {
minalpha = 50;
MovieClip.addListener(everyFrame);
everyFrame.onEnterFrame = function () {
if (this._x>x) {
this.xdiff = (this._x-x);
this.xudiff = this.xdiff/speed;
this._x -= this.xudiff;
} else {
this.xdiff = (x-this._x);
this.xudiff = this.xdiff/speed;
this._x += this.xudiff;
}
if (this._y>y) {
this.ydiff = (this._y-y);
this.yudiff = this.ydiff/speed;
this._y -= this.yudiff;
} else {
this.ydiff = (y-this._y);
this.yudiff = this.ydiff/speed;
this._y += this.yudiff;
}
var dist = trig(initx, x, inity, y);
var nowdist = trig(initx, this._x, inity, this._y);
var perc = nowdist/dist;
perc = 1-perc;
this._width = initwidth*perc;
this._height = initheight*perc;
minalpha = minalpha/100;
var alphaperc = perc + minalpha;
this._alpha = 100*alphaperc;
if(Math.round(perc) == 0) {
this.removeMovieClip;
}
}
}
var barstroke1 = {width:1, color:0xFFFFFF, alpha:0}; // stroke for the front bars
var barcolor1 = {color:0xFFFFFF, alpha:100}; // fill for the front bars
i = 0;
//------------------------------------------------------------
//----------------------[ Frame Two ]-------------------------
//------------------------------------------------------------
createEmptyMovieClip("cross" + i, this.getNextHighestDepth());
var initx = randRange(-100,500);
var inity = randRange(-100,500);
var size = 20;
var width = 10;
eval("cross" + i).Cross(initx, inity, size, width, barstroke1, barcolor1);
var initsize = size*2 + width;
var x = randRange(-100,500);
var y = randRange(-100,500);
var speed = 20;
eval("cross" + i).fly2Point(x, y, speed, initsize, initsize, initx, inity);
i++;
//------------------------------------------------------------
//---------------------[ Frame Three ]------------------------
//------------------------------------------------------------
gotoAndPlay(2);
Ok first off thats my code :) Its part of a movie clip that should create a cross and then make that cross zoom towards a random point on the screen, (the random point part is merely for testing pourposes at the moment), the cross should proceed to decrease in size and become less opaque as it gets closer to the point. It does all that fine. The problem becomes when trying to create more than one movie clip.
Since the variables in frame two arent specific to the movie clip then the alpha size and zoom position, change on every instance of the movie clip. I have tried using this for frame two:
createEmptyMovieClip("cross" + i, this.getNextHighestDepth());
with(eval("cross" + i)) {
this.initx = randRange(-100,500);
this.inity = randRange(-100,500);
this.size = 20;
this.width = 10;
this.Cross(this.initx, this.inity, this.size, this.width, barstroke1, barcolor1);
this.initsize = this.size*2 + this.width;
this.x = randRange(-100,500);
this.y = randRange(-100,500);
this.speed = 200;
this.fly2Point(this.x, this.y, this.speed, this.initsize, this.initsize, this.initx, this.inity);
}
i++;
But I end up with the same problem. Any help on this issue would be greatly appreciated :)