class Ball { private var _mc:MovieClip; //Constructor: duplicates the counter in a new position, new name. function Ball(copyClip:MovieClip, sourceMc:String, px:Number, py:Number,scale:Number) { //Initialise the level counter if (_global.lvl == undefined) _global.lvl = 0; _mc = copyClip.duplicateMovieClip(sourceMc, _global.lvl); _mc._x = px; _mc._y = py; _mc._xscale = scale; _mc._yscale = scale; _global.lvl++; } private var d,d_1,d_2:Number; // This function should move ball from one column to another in an appropriate // bouncing fashion. Still a problem with this. For large m , the balls don't always // satisfy the close to destination condition. public function moveIt(sourceMc:MovieClip,destx:Number,desty:Number):Void { d_1 = destx-sourceMc._x; d_2 = desty-sourceMc._y; d = Math.sqrt(d_1*d_1+d_2*d_2); function GO(e_1:Number,e_2:Number,e:Number):Void { //trace((destx-sourceMc._x)*(destx-sourceMc._x)+(desty-sourceMc._y)*(desty-sourceMc._y)); //if (( (destx-sourceMc._x)*(destx-sourceMc._x)+(desty-sourceMc._y)*(desty-sourceMc._y))>50) if ((destx-sourceMc._x)*(destx-sourceMc._x)>100 || (desty-sourceMc._y)*(desty-sourceMc._y)>100) { //trace("destx="+destx); //trace("destx="+desty); //trace("mc._x="+sourceMc._x); //trace("mc._y="+sourceMc._y); sourceMc._x +=4*e_1/e; sourceMc._y +=4*e_2/e; } else { sourceMc._x = destx; sourceMc._y = desty; clearInterval(MOVEit); } } var MOVEit:Number = setInterval(GO,1,d_1,d_2,d); //clearInterval(MOVEit); } }