PDA

View Full Version : creating class....help ...............


rlee
11-20-2002, 05:58 AM
function Ball() {
}
Ball.prototype = new MovieClip();
Ball.prototype.location = function() {
this._x = Math.random()*100;
this._y = _x;
};

myBall = new Ball();
output = myBall.location(5,5);

trace(output);


what's wrong?? should i put arguement? return??

???

jimburton
11-20-2002, 09:37 AM
not sure what you want to do but the location method doesn't return anything, just moves your object, so you should trace myBall._x if you want to see where it is...

and change the line
this._y = _x;

to

this._y = this._x;

or this._x = this._y = Math.random()*100;

simontheak
11-20-2002, 01:32 PM
Ok, I've only just started learning about classes, so I may be wrong here.:rolleyes:

But if you're going to call the function using

output = myBall.location(5,5);

Then surely your function is going to need to be prepared to accept two arguments. The way you've got it as it is, it's not accepting any.

Also if you want to assign the result to a variable, your function is going to need a return statement in it ... but then looking at the bottom of your post, it sounds as though you might know this already