Learning English Online, Free English Lessons For Everyone
_Sponsors_
___ ______

Flash CS3: Lesson 2: Using the startDrag and stopDrag methods PDF  | Print |  E-mail
Saturday, 02 April 2011 18:44

Flash CS3: Lesson 2: Using the startDrag and stopDrag methods

Display Objects have methods called startDrag and stopDrag that make it easy to add this type of interface quickly to any application. The following additional code will add this functionality. The basic idea is that when the mouse is pressed down over our circle (the sprite named "myPoint"), the startDrag method is called and when the mouse is let up over our circle, the stopDrag method is called. Both startDrag and stopDrag are built-in methods of the Sprite class, so nothing else is needed.

 

// Part 2 -- Add drag-and-drop functionality

o nothing else is needed.

 

 

// Part 2 -- Add drag-and-drop functionality

 

myPoint.addEventListener(MouseEvent.MOUSE_DOWN, startMove);

 

function startMove(evt:MouseEvent):void {

myPoint.startDrag();

}

 

myPoint.addEventListener(MouseEvent.MOUSE_UP, stopMove);

 

function stopMove(e:MouseEvent):void {

myPoint.stopDrag();

}

Download

 

myPoint.addEventListener(MouseEvent.MOUSE_DOWN, startMove);

 

function startMove(evt:MouseEvent):void {

myPoint.startDrag();

}

 

myPoint.addEventListener(MouseEvent.MOUSE_UP, stopMove);

 

function stopMove(e:MouseEvent):void {

myPoint.stopDrag();

}

Download

Notes

  • This is quick because it requires so little code.
  • The dragging looks a little rough.
  • The dragging goes beyond the boundaries of the box. This can be remedied by adding an argument to the startDrag method call that specifies a rectangular boundary that the object cannot be dragged beyond. To use this, you should look up the help file for startDrag and be prepared to follow up by reading up on the Rectangle class.
  • It is not clear from this simple example, but we cannot easily control other actions that should be completed during the dragging of the ball. For example, if we want a line to be traced having the ball as one endpoint, it is not easy to have this line updated continuously as the ball is dragged, as one would want.

 

__Please, Click here to have another Lesson about Drag-and-Drop in Flash CS3____

Last Updated on Wednesday, 13 April 2011 16:11
  ________


_____
We have 74 guests online

If you don't see anything in the middle of this page, you may need the latest Flash plug-in.
It only takes a few moments to
Download it FREE at Adobe.com. get adobe Flash player

Teaching English For Kids In Primary School

Stydying English Online For Everyone

Game for Kids


Home || Misterduncan|| Flash Cards || Songs For Kids|| Free Games || Learn English with GOGO|| Teaching English For Childern|| ESL/EFL Kids Course ||
Designed by Learning English Online. Designed by: Free Joomla Theme, mysql. Valid XHTML and CSS.