Return to Snippet

Revision: 54208
at December 14, 2011 22:15 by mgraph


Updated Code
/* to USE IT
import com.addMouseEvent;
addMouseEvent(myBtn,startGame,false);
function startGame(me:MouseEvent){
	switch(me.type){
		case "mouseOver":
			trace("over");
		break;
		case "mouseOut":
			trace("out");
		break;
		case "mouseDown";
			trace("down");
		break;
	}
}
*/
package com{
	import flash.events.MouseEvent;

	public function addMouseEvent(_targ,_func,_fader:Boolean=false):void {
		_targ.buttonMode = true;
		_targ.mouseChildren = false;
		_targ.addEventListener(MouseEvent.MOUSE_DOWN, _func);
		var overFunc = _func;
		if (_fader) {
			overFunc = fader;
		}
		_targ.addEventListener(MouseEvent.MOUSE_OVER, overFunc);
		_targ.addEventListener(MouseEvent.MOUSE_OUT, overFunc);
		function fader(me:MouseEvent) {
			switch (me.type) {
				case "mouseOver" :
					me.currentTarget.alpha = 0.8;
					break;
				case "mouseOut" :
					me.currentTarget.alpha = 1;
					break;
			}
		}
	}

}

Revision: 54207
at December 14, 2011 22:14 by mgraph


Updated Code
/* to USE IT
import com.addMouseEvent;
addMouseEvent(myBtn,startGame,false);
function startGame(me:MouseEvent){
	switch(me.type){
	case "mouseOver":
		trace("over");
	break;
	case "mouseOut":
		trace("out");
	break;
	case "mouseDown";
		trace("down");
	break;
	}
}
*/
package com{
	import flash.events.MouseEvent;

	public function addMouseEvent(_targ,_func,_fader:Boolean=false):void {
		_targ.buttonMode = true;
		_targ.mouseChildren = false;
		_targ.addEventListener(MouseEvent.MOUSE_DOWN, _func);
		var overFunc = _func;
		if (_fader) {
			overFunc = fader;
		}
		function fader(me:MouseEvent) {
			switch (me.type) {
				case "mouseOver" :
					me.currentTarget.alpha = 0.8;
					break;
				case "mouseOut" :
					me.currentTarget.alpha = 1;
					break;
			}
		}
	}

}

Revision: 54206
at December 14, 2011 22:09 by mgraph


Initial Code
package com{
	import flash.events.MouseEvent;

	public function addMouseEvent(_targ,_func,_fader:Boolean=false):void {
		_targ.buttonMode = true;
		_targ.mouseChildren = false;
		_targ.addEventListener(MouseEvent.MOUSE_DOWN, _func);
		var overFunc = _func;
		if (_fader) {
			overFunc = fader;
		}
		function fader(me:MouseEvent) {
			switch (me.type) {
				case "mouseOver" :
					me.currentTarget.alpha = 0.8;
					break;
				case "mouseOut" :
					me.currentTarget.alpha = 1;
					break;
			}
		}
	}

}

Initial URL

                                

Initial Description
simple as3 class that help you to avoid repeat add MouseEvent each time

Initial Title
Flash As3 AddMouseEvent Class

Initial Tags
class

Initial Language
ActionScript 3