hey i have this code for selecting dots on the screen by clicking and draging but when i use the arrow key to move one of the dots it stops working does anyone know why this is?
k = new Object();
// variable stating if I clicked the mouse
clicked = false;
// variable stating if I am dragging the mouse
dragging = false;
select = false;
for (i=0; i<4; i++) {
nano = this.attachMovie("ball", "ball"+i, this.getNextHighestDepth());
nano._x = Math.random()*(Stage.width-nano._width);
nano._y = Math.random()*(Stage.height-nano._height);
nano.onRelease = function() {
target = this;
this.gotoAndStop(2);
};
nano.onReleaseOutside = function() {
target = this;
this.gotoAndStop(2);
};
nano.onEnterFrame = function() {
if (dragging) {
if ((this._x+10>Math.min(click_x, posx)) and (this._x-10<Math.max(click_x, posx)) and (this._y+10>Math.min(click_y, posy)) and (this._y-10<Math.max(click_y, posy))) {
target = this;
this.gotoAndStop(2);
select = true;
} else {
if (!select) {
this.gotoAndStop(1);
}
}
if (select) {
selmovie.clear();
}
}
};
nano.gotoAndStop(1);
}
// creation of a movieclip where I will draw the square made by mouse dragging
_root.createEmptyMovieClip("selmovie",_root.getNextHighestDepth());
// function to be executed every time I press the mouse
_root.onMouseDown = function() {
click_x = _root._xmouse;
click_y = _root._ymouse;
clicked = true;
xmouse = _root._xmouse;
ymouse = _root._ymouse;
if (!dragging) {
for (x=0; x<=4; x++) {
dist_x = _root["ball"+x]._x-xmouse;
dist_y = _root["ball"+x]._y-ymouse;
distance = Math.floor(Math.sqrt(dist_x*dist_x+dist_y*dist_y));
if (distance>_root["ball"+x]._width*2) {
_root["ball"+x].gotoAndStop(3);
select = false;
}
}
}
};
k.onKeyDown = function() {
target.onEnterFrame = mover;
var k = Key.getCode();
if (k == Key.UP) {
target.yspeed = -5;
target.xspeed = 0;
target.gotoAndStop(2);
} else if (k == Key.LEFT) {
target.yspeed = 0;
target.xspeed = -5;
target.gotoAndStop(2);
} else if (k == Key.DOWN) {
target.xspeed = 0;
target.yspeed = 5;
target.gotoAndStop(2);
} else if (k == Key.RIGHT) {
target.yspeed = 0;
target.xspeed = 5;
target.gotoAndStop(2);
} else if (k == Key.SHIFT) {
target.yspeed = 0;
target.xspeed = 0;
target.gotoAndStop(3);
}
};
Key.addListener(k);
function mover() {
this._x += this.xspeed;
this._y += this.yspeed;
if (this._x<0-this._width) {
this._x = Stage.width;
}
if (this._x>Stage.width) {
this._x = 0-this._width;
}
if (this._y<0-this._height) {
this._y = Stage.height;
}
if (this._y>Stage.height) {
this._y = 0-this._height;
}
}
// function to be executed every time I move the mouse
_root.onMouseMove = function() {
// if I clicked...
if (clicked) {
if (!select) {
// I am dragging
dragging = true;
// saving acutal x and y mouse positions
posx = _root._xmouse;
posy = _root._ymouse;
// clearing the movieclip I am about to draw on
selmovie.clear();
// setting the line style of the movieclip
selmovie.lineStyle(2,0x000000,50);
// setting the filling of the movieclip
selmovie.beginFill(0xff0000,30);
// drawing a square connecting the point I first clicked on and the point I am currently on
selmovie.moveTo(click_x,click_y);
selmovie.lineTo(posx,click_y);
selmovie.lineTo(posx,posy);
selmovie.lineTo(click_x,posy);
selmovie.lineTo(click_x,click_y);
// at this time the square is filled, and you can omit next line
selmovie.endFill();
}
}
};
// function to be executed every time I release the mouse
_root.onMouseUp = function() {
// clearing the drag square
selmovie.clear();
// I am not clicking
clicked = false;
// I am not dragging
dragging = false;
};
http://[URL=“http://www.swfcabin.com/open/1273634526”]www.swfcabin.com/open/1273634526