# Random Floaty Firefly-Like Movement

**URL:** https://forum.kirupa.com/t/random-floaty-firefly-like-movement/92299
**Category:** Uncategorized
**Created:** [October 15, 2003, 4:25pm UTC](https://forum.kirupa.com/t/random-floaty-firefly-like-movement/92299 "2003-10-15T16:25:40Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![quik](https://avatars.discourse-cdn.com/v4/letter/q/e19b73/32.png) [@quik](https://forum.kirupa.com/u/quik)
#### Post date: [October 15, 2003, 4:25pm UTC](https://forum.kirupa.com/t/random-floaty-firefly-like-movement/92299/1 "2003-10-15T16:25:40Z")

</div>

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(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\*, 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.\_y_2.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]
