Skip to content

Basic Button Setup

This is the basic ActionScript 3.0 set up I do for my buttons.
It is good for when you have a lot of buttons using the same rollover effect.

// basic calls
enableCtrlButton( mMovicClipWithAButtonInIt, myAwsomeFunction );
// later on you might want to cancel this
disableCtrlButton( mMovicClipWithAButtonInIt, myAwsomeFunction ); 

// this is unique because of the mouse down events
function enableCtrlButton( obj:Object , fun:Function )
{
	// -- action
	obj.addEventListener (	MouseEvent.MOUSE_DOWN, fun );
	obj.addEventListener (	MouseEvent.MOUSE_UP, fun );
	obj.addEventListener (	MouseEvent.MOUSE_OVER, CtrlOverAni );
	obj.addEventListener (	MouseEvent.MOUSE_OUT , CtrlOutAni );
}

// -- animation
function CtrlOverAni( e:Event )
{
	var mc:Object = e.target.parent;
	//trace( "{ BTN OVER " + mc.name + " }" );
}
function CtrlOutAni( e:Event )
{
	var mc:Object = e.target.parent;
	//trace( "{ BTN OUT " + mc.name + " }" );
}

// -- DISABLE PAGE BUTTONS
function disableCtrlButton( obj:Object , fun:Function )
{
	// -- remove actions
	obj.removeEventListener (	MouseEvent.MOUSE_DOWN, fun );
	obj.removeEventListener (	MouseEvent.MOUSE_UP, fun );
	obj.removeEventListener (	MouseEvent.MOUSE_OVER, CtrlOverAni );
	obj.removeEventListener (	MouseEvent.MOUSE_OUT , CtrlOutAni );

	// turn off hand cursor
	obj.useHandCursor = false;
}

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*