[FMX] User defined functions

Hi,

I am working on a program that has to do with random motion. To see what I have so far visit http://noxnerd.tripod.com/bubbles1.html.

I wrote the code for motion straight into the action panel of the bubble symbol and simply duplicated the symbol alot to add more bubbles. What I wanted to do is change all that code into global functions that can simply be called by each movie clip thereby cleaning it up alot and making it more modifyable. The problem is that I can’t figure out how to write and call the functions properly.

Here is what I have:

Layers:
Actions: where the functions are defined
Bubble: contains symbols (clip calling the functions)
Background: just the background

Code:
[The following is what I have for functions in the Actions layer]

_global.movement.move = function (xmove, ymove) {

//“this._x” is supposed to be of the clip being moved
this._x += xmove;
this._y += ymove;
}

// pass the x coord of clip and x coord of destination

_global.movement.initCheckx = function (x, x2){
if((x >= x2 - 3) && (x <= x2 + 3)) {

	x2 = random(51);

	if(random(2) == 1) {x2 += x;}

	else {x2 = x - x2;}

	if(x2 &gt;= 700) x2 = 700;

	if(x2 &lt;= 0) x2 = 0;

	return (x2 - x) / 100;		
}

}
// pass the y coord of clip and y coord of destination

_global.movement.initChecky = function (y, y2){

if((y &gt;= y2 - 3) && (y &lt;= y2 + 3)) {	

	y2 = random(51);

	if(random(2) == 1) {y2 += y;}

	else {y2 = y - y2;}

	if(y2 &gt;= 400) y2 = 700;

	if(y2 &lt;= 0) y2 = 0;

	return (y2 - y) / 100;
}

}

[The following code is the code to call the functions]

onClipEvent (load) {
this.pointx = 0;

this.pointy = 0;

this.movex = _global.movement.initCheckx(this._x,this.pointx);

this.movey = _global.movement.initChecky(this._y,this.pointy);
}

onClipEvent (enterFrame) {

this.movex = _global.movement.initCheckx(this._x,this.pointx);

this.movey = _global.movement.initChecky(this._y,this.pointy);

_global.movement.move(this.movex, this.movey);
}

So, the functions aren’t even being called. I’m not sure of the syntax to declare those functions as public or to call them with the bubble clips.

Any help would be greatly appreciated.

Andrew

Thanks for the help, that fixed the problem and also resolved my trouble of pass by reference as I can perform operations on the “this.” varaibles.

Thanks again,

Andrew