PDA

View Full Version : TextFeild in a MovieClip being weird


archonic
07-24-2009, 06:48 AM
Maybe this is a weird thing in AS3 or maybe 2:41 am. (it is exactly 2:41 am).

Here's my code to place text menu items (from XML) on the stage with appropriate listeners and such.


public function parseXML(menuInput:XML):void
{
var linkList:XMLList = menuInput.item;
var xIndex:uint = 0;
for(var i:uint = 0; i<linkList.length(); i++)
{
var newTextItem = new TextField();
newTextItem.selectable = false;

newFormat.size = 14;
newFormat.font = "Whitney Book";
newTextItem.defaultTextFormat = newFormat;
newTextItem.antiAliasType = AntiAliasType.ADVANCED;

newTextItem.text = menuInput.item[i].title.text();
newTextItem.autoSize=TextFieldAutoSize.LEFT;
newTextItem.x = xIndex + 20*i;
xIndex += newTextItem.width;

var menuItem_mc = new MovieClip();
menuItem_mc.addChild(newTextItem);
menuItem_mc.name = "menuItem"+i;
menuItem_mc.addEventListener( MouseEvent.MOUSE_OVER, menuItemOver );
menuItem_mc.buttonMode = true;

addChild(menuItem_mc);
}
}

public function menuItemOver(e:MouseEvent):void
{
trace("MouseOver::"+e.target);
trace("MouseOver::"+e.target.name);
menuItemOverBG.width = e.target.width+10;
menuItemOverBG.x = e.target.x-5;
}


The output is this:
MouseOver::[object TextField]
MouseOver::instance3

Why would the output of e.target for a movie clip be a textfield when the textfield is it's child? It's screwing up my buttonMode :mad:

werehunt
07-24-2009, 06:59 AM
menuItem_mc.mouseChildren = false;

archonic
07-24-2009, 07:10 AM
yep, definately 3:16 am. stupid mouse children. think they own the place. thanks!

henke37
07-25-2009, 02:12 PM
It is the target because it's the leaf of the display list. The rest is just containers. If you want a reffernce to the object that you listened on, use the currentTarget property instead.