Return to Kroll Design home page

Flash Tutorials (with .FLA files included)

 
« Return

ActionScript 3

buttonMode to create a hand cursor when over a dynamic text box

Movie clips, even clickable movie clips, default to having an arrow cursor, not a hand cursor. To make the movie clip act more like a button and give it a hand cursor, use mcClip.buttonMode = true, where myClip is your movie clip name. However, setting buttonMode to true isn't sufficient to have the hand cursor appear over dynamic text boxes that reside within the movie clip. To achieve the hand cursor over the text box and all parts of the movie clip, you also need to set mouseChildren to false. This example also shows how to dynamically change the color of a movie clip using colorTransform.

Download the FLA file



myClip_mc.myTextBox_txt.text = "This is dynamic text.";
myClip_mc.myTextBox_txt.wordWrap = true;

var colorTransformOver:ColorTransform = myClip_mc.rectangleFill_mc.transform.colorTransform;
colorTransformOver.color = 0xAAAAAA;

var colorTransformOut:ColorTransform = myClip_mc.rectangleFill_mc.transform.colorTransform;
colorTransformOut.color = 0x999999;

// This is necessary but not sufficient to cause hand cursor over text box:
myClip_mc.buttonMode = true; 

// This is necessary also, and the combo of this and the prior statement are sufficient: 
myClip_mc.mouseChildren = false; 

// Given that you already have the prior two statements, it's not even necessary to
// set selectable to false:
myClip_mc.myTextBox_txt.selectable = false; 

myClip_mc.addEventListener(MouseEvent.MOUSE_OVER, mouseoverEffect);
function mouseoverEffect(myEvent:MouseEvent)
{
	myClip_mc.myTextBox_txt.text = "You are now mousing over the movie clip";
	myClip_mc.rectangleFill_mc.transform.colorTransform = colorTransformOver;
}

myClip_mc.addEventListener(MouseEvent.MOUSE_OUT, mouseoutEffect);
function mouseoutEffect(myEvent:MouseEvent)
{
	myClip_mc.myTextBox_txt.text = "You are no longer mousing over the movie clip";
	myClip_mc.rectangleFill_mc.transform.colorTransform = colorTransformOut;
}

myClip_mc.addEventListener(MouseEvent.MOUSE_DOWN, mousedownEffect);
function mousedownEffect(myEvent:MouseEvent)
{
	myClip_mc.myTextBox_txt.text = "You are pressing the mouse button down while in the movie clip";
	myClip_mc.x += 2;
	myClip_mc.y += 2;
}

myClip_mc.addEventListener(MouseEvent.CLICK, mouseClick);
function mouseClick(myEvent:MouseEvent)
{
	myClip_mc.myTextBox_txt.text = "You clicked the movie clip.";	
	myClip_mc.x -= 2;
	myClip_mc.y -= 2;
}


 
« Return


©2012 Kroll Design    info@KrollDesign.net    781.910.3694
Last modified: 12/31/1969 7:00 PM