[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

instead of using this
_global.movement.move = function (xmove, ymove) {
use this


MovieClip.prototype.move = function(xmove,ymove){

}

that will allow you to refer to the clips as “this” I hope that helps a little bit.

p.s. try to use the ActionScript tag, it makes it a lot easier to view code (just put AS between [##] these to start, and then AS between these [/##] to end (where ##=AS.))

Please, use the [as**]

** tags. Its hard to understand long pieces of code without them.

nice.
11-09-2003 03:17 AM
11-09-2003 03:18 AM
:smiley:
love it when that happens.
(and d*mn you for getting around the rendering;))

:beam:

Will do, its my first post here.

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