class andyDot { // properties that need to be stored private var timeline:MovieClip; private var movie:MovieClip; public function andyDot(_timeline:MovieClip, level:Number) { timeline = _timeline; createGraphic(level); } private function createGraphic(level:Number) { var graphic = Math.floor(Math.random()*3); // random numbers for position // note that Stage is global and view by all classes without declaration var posx = nCheckBounds(Stage.width,Math.floor(Math.random()*Stage.width),"x"); var posy = nCheckBounds(Stage.height,Math.floor(Math.random()*Stage.height),"y"); // attach the movieclip movie = timeline.attachMovie("Dot"+graphic, "instDot"+level, level, {_x:posx, _y:posy}); // create eventHandlers for the movieclip movie.onRollOver = function() { var bMove = true; var bCond = false; var nOrigX:Number = this._x; var nOrigY:Number = this._y; var sMouseX:String = "-"; var sMouseY:String = "-"; trace(this._x + "-" + this._xmouse); if (this._xmouse >= 30) {sMouseX = "E";} if (this._xmouse < 30) {sMouseX = "W";} if (this._ymouse >= 30) {sMouseY = "N";} if (this._ymouse < 30) {sMouseY = "S";} //move while(bMove) { if (sMouseX == "E" && nOrigX > 0) { this._x = this._x -1; if (nOrigX - this._x > 30){bMove = false;} bCond = true; } if (sMouseX == "W" && nOrigX < (Stage.width-60)) { this._x = this._x +1; if (this._x - nOrigX > 30){bMove = false;} bCond = true; } if (sMouseY == "N" && nOrigY > 0) { this._y = this._y -1; if (nOrigY - this._y > 30){bMove = false;} bCond = true; } if (sMouseY == "S" && nOrigY < (Stage.height-60)) { this._y = this._y +1; if (this._y - nOrigY > 30){bMove = false;} bCond = true; } trace(sMouseX + "--" + nOrigX + "---" + this._x); //if no move is necessary, break out of while loop if (bCond == false) {bMove = false;} } //end while loop for movement //cirrect for edges if (this._x < 0) {this._x = 0;} if (this._x > (Stage.width-60)) {this._x = (Stage.width-60);} if (this._y < 0) {this._y = 0;} if (this._y > (Stage.height-60)) {this._y = (Stage.height-60);} } } //end createGrpahic private function nCheckBounds(nStage:Number, nPos:Number, sType:String) { var nNewPos:Number = nPos; var bOutOfBounds:Boolean = true; while (bOutOfBounds) { if (nNewPos < 0) { nNewPos = nNewPos +1; } else if (nNewPos > (nStage-60)) { nNewPos = nNewPos -1; } else { bOutOfBounds = false; } } return (nNewPos); } } //end Class