Hi good people of Kirupa!
I’m writing a very simple class, which is meant to affect the movieClip “ball_mc”. All I want it to do is to randomize its (ball_mc) properties (._alpha, ._x, ._y etc).
import mx.utils.Delegate;
class move {
private var t_mc:MovieClip;
public function move(t:MovieClip) {
t_mc = t;
randomize();
}
private function randomize():Void {
t_mc.onEnterFrame = function() {
this._x += randNum(-100, 100);
}
}
private function randNum(min:Number, max:Number):Number {
var n:Number = (min + Math.floor(Math.random() * (max - min)));
trace(n);
return n;
}
}
I guess this could be a job for Mr. Delegate, but I don’t get it to work properly. The problem is that is won’t call the randNum function, due to scoping issues I suspect. The “onEnterFrame” works fine.
Any hints guys? Thanks in advance.