I’m using a bunch of code that was on kirupa for random movement, I’ve used it in the past and I can’t understand why it isn’t working?
Thanks in advance!
I orginally posted this on flashkit forums but I seem to never get any replies? Maybe I ask stupid questions?
[SIZE=1]Code Below:[/SIZE]
[AS]
var items:Array = [‘Painting’, ‘Sculpture’, ‘Printmaking’, ‘Photography’];
depth = 0;
ButtonLabelText = new TextFormat();
ButtonLabelText.bold = false;
ButtonLabelText.color = 0x333333;
ButtonLabelText.font = “Arial”;
ButtonLabelText.size = 9;
function getdistance(x, y, x1, y1) {
var run;
var rise;
run = x1-x;
rise = y1-y;
return (_root.hyp(run, rise));
}
function hyp(a, b) {
return (Math.sqrt(aa+bb));
}
MovieClip.prototype.reset = function ()
{
width = 450;
height = 250;
var dist;
var norm;
this.x = this._x;
this.y = this._y;
this.speed = 1;
this.targx = Math.random() * width;
this.targy = Math.random() * height;
dist = _root.getdistance(this.x, this.y, this.targx, this.targy);
norm = this.speed / dist / 10;
this.diffx = (this.targx - this.x) * norm;
this.diffy = (this.targy - this.y) * norm;
}
MovieClip.prototype.move = function() {
if (_root.getdistance(this.x, this.y, this.targx, this.targy)<this.speed) {
this.x = this.x+this.diffx;
this.y = this.y+this.diffy;
} else {
this.x = this.targx;
this.y = this.targy;
if (this.t) {
this.t = getTimer();
}
if (getTimer()-this.t<0) {
this.reset();
this.t = 0;
}
}
this._x = this.x;
this._y = this.y;
};
createFire = function () {
_root.createEmptyMovieClip(“fire_flies”, depth++);
for (i=0; i<items.length; i++) {
root.fire_flies.attachMovie(“firefly”, "firefly"+items*, depth++);
root.fire_flies["firefly"+items*].createTextField(“section”, depth++, 0, -3, 200, 15);
root.fire_flies["firefly"+items*].section.selectable = false;
root.fire_flies["firefly"+items*].section.setNewTextFormat(ButtonLabelText);
root.fire_flies["firefly"+items*].section.text = items*;
root.fire_flies["firefly"+items*].section._visible = false;
root.fire_flies["firefly"+items*].section._x = root.fire_flies["firefly"+items*].section._x+10;
root.fire_flies["firefly"+items*].section._y = root.fire_flies["firefly"+items*].section._y2.5;
root.fire_flies["firefly"+items]._x = i*root.fire_flies["firefly"+items*]._width;
root.fire_flies["firefly"+items*]._y = i*root.fire_flies["firefly"+items*]._height;
root.fire_flies["firefly"+items*].onEnterFrame = move();
trace(root.fire_flies["firefly"+items*]);
}
};
createFire();
[/AS]