http://www.sendspace.com/file/351r2w - Download link

The code
CODE
/////////////////
var squarePress = false;
border_mc.onEnterFrame = function() {
/////////////////////////////////
//Moves "square" to the left
/////////////////////////////////
if (square._x>border_mc._x) {
if (Key.isDown(Key.LEFT)) {
square._x -= 5;
}
}
/////////////////////////////////
//Moves "square" to the buttom
/////////////////////////////////
if (square._y<border_mc._y+border_mc._height-square._height) {
if (Key.isDown(Key.DOWN)) {
square._y += 5;
}
}
/////////////////////////////////
//Moves "square" to the top
/////////////////////////////////
if (square._y>border_mc._y) {
if (Key.isDown(Key.UP)) {
square._y -= 5;
}
}
/////////////////////////////////
//Moves "square" to the right
/////////////////////////////////
if (square._x<border_mc._x+border_mc._width-square._width) {
if (Key.isDown(Key.RIGHT)) {
square._x += 5;
}
}
/////////////////////////////////
//Moves "square" with the mouse // Start
/////////////////////////////////
if (squarePress == true) {
//////////////////////////////////////////
//limits mouse x placement to the left
/////////////////////////////////////////////
if (_root._xmouse>border_mc._x+square._width/2 && _root._xmouse<border_mc._x+border_mc._width-square._width) {
_root.square._x = _root._xmouse-square._width/2;
} else {
if (_root._xmouse<border_mc._x+border_mc._width/2) {
_root.square._x = border_mc._x;
} else {
_root.square._x = border_mc._x+border_mc._width-square._width;
}
}
////
//limits mouse Y placement to the top
////
if (_root._ymouse>border_mc._y+square._width/2 && _root._ymouse<border_mc._y+border_mc._height-square._height) {
_root.square._y = _root._ymouse-square._height/2;
} else {
if (_root._ymouse<border_mc._y+border_mc._width/2) {
_root.square._y = border_mc._y;
} else {
_root.square._y = border_mc._y+border_mc._height-square._height;
}
}
}
};
/////////////////////////////////////////
// grab the square
//////////////////////////////////
square.onPress = function() {
squarePress = true;
};
square.onRelease = function() {
squarePress = false;
};
square.onReleaseOutside = function() {
squarePress = false;
};
var squarePress = false;
border_mc.onEnterFrame = function() {
/////////////////////////////////
//Moves "square" to the left
/////////////////////////////////
if (square._x>border_mc._x) {
if (Key.isDown(Key.LEFT)) {
square._x -= 5;
}
}
/////////////////////////////////
//Moves "square" to the buttom
/////////////////////////////////
if (square._y<border_mc._y+border_mc._height-square._height) {
if (Key.isDown(Key.DOWN)) {
square._y += 5;
}
}
/////////////////////////////////
//Moves "square" to the top
/////////////////////////////////
if (square._y>border_mc._y) {
if (Key.isDown(Key.UP)) {
square._y -= 5;
}
}
/////////////////////////////////
//Moves "square" to the right
/////////////////////////////////
if (square._x<border_mc._x+border_mc._width-square._width) {
if (Key.isDown(Key.RIGHT)) {
square._x += 5;
}
}
/////////////////////////////////
//Moves "square" with the mouse // Start
/////////////////////////////////
if (squarePress == true) {
//////////////////////////////////////////
//limits mouse x placement to the left
/////////////////////////////////////////////
if (_root._xmouse>border_mc._x+square._width/2 && _root._xmouse<border_mc._x+border_mc._width-square._width) {
_root.square._x = _root._xmouse-square._width/2;
} else {
if (_root._xmouse<border_mc._x+border_mc._width/2) {
_root.square._x = border_mc._x;
} else {
_root.square._x = border_mc._x+border_mc._width-square._width;
}
}
////
//limits mouse Y placement to the top
////
if (_root._ymouse>border_mc._y+square._width/2 && _root._ymouse<border_mc._y+border_mc._height-square._height) {
_root.square._y = _root._ymouse-square._height/2;
} else {
if (_root._ymouse<border_mc._y+border_mc._width/2) {
_root.square._y = border_mc._y;
} else {
_root.square._y = border_mc._y+border_mc._height-square._height;
}
}
}
};
/////////////////////////////////////////
// grab the square
//////////////////////////////////
square.onPress = function() {
squarePress = true;
};
square.onRelease = function() {
squarePress = false;
};
square.onReleaseOutside = function() {
squarePress = false;
};