Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

actionscript drag and pan acorss a large image

This assumes the registration point is at the top left.

replace MY_MC with the name of a movieClip on your stage.

   1  
   2  import mx.utils.Delegate;
   3  grav = 0.82
   4  img = MY_MC
   5  mouseListener = new Object();
   6  mouseListener.onMouseDown = Delegate.create(this,mouse_down);
   7  mouseListener.onMouseMove = Delegate.create(this,e_point);
   8  mouseListener.onMouseUp   = Delegate.create(this,mouse_up);
   9  Mouse.addListener(mouseListener);
  10  
  11  
  12  function s_point()
  13  {
  14  	sx_point = _xmouse;
  15  	sy_point = _ymouse;
  16  }
  17  
  18  function mouse_down()
  19  {
  20  	pressed = true;
  21  	s_point();
  22  }
  23  
  24  function mouse_up()
  25  {
  26  	pressed = false;
  27  }
  28  
  29  function e_point()
  30  {
  31  		if(pressed)
  32  		{
  33  			ex_point = _xmouse - sx_point
  34  			ey_point = _ymouse - sy_point
  35  		}
  36  }
  37  
  38  function onEnterFrame()
  39  {
  40  	ex_point*=grav;
  41  	ey_point*=grav;
  42  	
  43  	img._x+=ex_point;
  44  	img._y+=ey_point;
  45  	
  46  	if (Math.abs(img._x) > img._width - Stage.width) img._x = (img._width - Stage.width)*-1;
  47  	if (Math.abs(img._y) > img._height - Stage.height) img._y = (img._height - Stage.height)*-1;
  48  	if (img._x > 0) img._x = 0;
  49  	if (img._y > 0) img._y = 0;
  50  }
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS