Jump to content


Photo
- - - - -

[Flash] Moveing Mc's Useing ActionScript


  • Please log in to reply
No replies to this topic

#1 wm.AngelEyes

wm.AngelEyes

    Jedi In Training

  • Members
  • PipPip
  • 452 posts
  • Gender:Male
  • Location:Denmark

Posted 25 April 2007 - 06:31 AM

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

Posted Image


The 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;
};

Edited by Angel Eyes, 25 April 2007 - 06:52 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users