PDA

View Full Version : Random Floaty Firefly-Like Movement.



quik
October 15th, 2003, 12:25 PM
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?

Code Below:


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(a*a+b*b));
}
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[i], depth++);
_root.fire_flies["firefly_"+items[i]].createTextField("section", depth++, 0, -3, 200, 15);
_root.fire_flies["firefly_"+items[i]].section.selectable = false;
_root.fire_flies["firefly_"+items[i]].section.setNewTextFormat(ButtonLabelText);
_root.fire_flies["firefly_"+items[i]].section.text = items[i];
_root.fire_flies["firefly_"+items[i]].section._visible = false;
_root.fire_flies["firefly_"+items[i]].section._x = _root.fire_flies["firefly_"+items[i]].section._x+10;
_root.fire_flies["firefly_"+items[i]].section._y = _root.fire_flies["firefly_"+items[i]].section._y*2.5;
_root.fire_flies["firefly_"+items[i]]._x = i*_root.fire_flies["firefly_"+items[i]]._width;
_root.fire_flies["firefly_"+items[i]]._y = i*_root.fire_flies["firefly_"+items[i]]._height;
_root.fire_flies["firefly_"+items[i]].onEnterFrame = move();
trace(_root.fire_flies["firefly_"+items[i]]);
}
};
createFire();

prstudio
October 15th, 2003, 02:05 PM
flashkit is too big to get any replies, welcome to your new Kirupaville home...someone will be with you shortly...please hold>

jingman
October 15th, 2003, 03:23 PM
Exactly what part doesn't work, that's a lot of code.

quik
October 15th, 2003, 07:56 PM
um, it don't float.

the movies are all created, the textboxes are created within them and the text is set with the style, all that is cool.

They just won't move though :|

jingman
October 15th, 2003, 08:02 PM
can you post the fla?

quik
October 15th, 2003, 08:06 PM
Cheers, uploaded the file to here (http://www.giraffaka.com/temp/fire_flies.fla)

jingman
October 15th, 2003, 08:12 PM
Can you save it in "Flash MX" format? (non mx2004).

I can't seem to open it.

quik
October 15th, 2003, 11:45 PM
uploaded the MX file to here (http://www.giraffaka.com/temp/fire_flies_MX.fla)

thanks :)

quik
October 17th, 2003, 05:11 AM
^bump