tutorials flash double_click

DoubleClick in AS3

Let’s how see how to use the MouseEvent.DOUBLE_CLICK event in the new AS3 framework.

All of the objects which can inherit the flash.display.InteractiveObject class benefit from all of the events linked to mouse actions, keyboard actions or the taking or loss of a focus by the user.

Numerous classes (such as Sprite, TextField, MovieClip, DisplayObjectContainer, etc..) can use methods, properties and specific events linked to direct interactions with graphical elements in the application by the user.

To use the MouseEvent.DOUBLE_CLICK event, you need to look carefully at the InteractiveObject class and to see if there is a virtual property doubleClickEnabled (Boolean) which will be false by default. As well as being able to make this property true you can also trap this type of event.

Remarks :

It is also possible to change the virtual property mouseEnabled which allows you to activate or deactivate events which are mouse-interaction specific, like MouseEvent.MOUSE_DOWN, MouseEvent.MOUSE_UP, etc.

If we want to go even further up in the inheritance chain of the InteractiveObject class we can see that with the Sprite class there exists a virtual buttonMode property which allows you to display or not a hand instead of the classic cursor when we roll over a Sprite broadcasting MouseEvent events! In AS1 and AS2 it was possible to use the useHandCursor property. This property remains in AS3 but it is imperative that the buttonMode property is set to true to be active!

To finish here is the example which illustrates this tutorial:

package
{
	import flash.display.Sprite;
	import flash.events.MouseEvent ;
 
	public class TestDoubleClick extends Sprite
	{
		// ----o Constructor
 
		public function TestDoubleClick()
		{
 
			var bt:Sprite = new Sprite() ;
			bt.x = 20 ;
			bt.y = 20 ;
 
			bt.buttonMode = true ; // activates the hand cursor in button mode in the Sprite!
 
			// bt.mouseEnabled = false ; // deactivates all mouse events
 
			bt.doubleClickEnabled = true ; // activates the doubleClick
 
			bt.graphics.lineStyle(2, 0xFFFFFF, 100) ;
			bt.graphics.beginFill(0xFF0000, 100) ;
			bt.graphics.drawRoundRect(0, 0, 60, 12, 4, 4) ;
			bt.graphics.endFill() ;
 
			bt.addEventListener(MouseEvent.DOUBLE_CLICK, onDoubleClick) ;
 
			addChild(bt) ;
 
		}
 
		// ----o Public Methods
 
		public function onDoubleClick(e:MouseEvent):void
		{
			trace("> " + e) ;
		}
 
	}
 
}

By EKAMELEON - ALCARAZ Marc (2006) You can find this tutorial and its comments on my blog.








Adobe Training center


Mediabox Training Centre © 2000 - 2008 All rights reserved.
Adobe Authorized Training Centre. State convention under number 25 14 02167 14.
Mediabox : SARL au capital de 62.000€ - Activity number: 25 14 02167 14 - SIRET : 493 716 468 00027
MEDIABOX, 102 Avenue des Champs Elysées, 75008 PARIS - Tel. +33(0)2.31.91.96.89 - Fax. +33(0)2.72.68.56.42