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:
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: