How do I know which Object I clicked?
- by Nick
Here's the deal: I'm working on a personal portfolio in AS3 and I've run into a problem which I can't seem to find a logical answer to. I want everything (well, most of it) to be editable with an XML file, including my menu. My menu is just a Sprite with some text on it and a Tweener-tween, no big deal. But, I forgot to think of a way how I can determine which menu-item I have clicked.
This is in my Main.as
private function xmlLoaded(e:Event):void {
xml = e.target.xml;
menu = new Menu(xml);
menu.x = 0;
menu.y = stage.stageHeight / 2 - menu.height / 2;
addChild(menu);
}
In Menu.as
public function Menu(xml:XML) {
for each (var eachMenuItem:XML in xml.menu.item) {
menuItem = new MenuItem(eachMenuItem);
menuItem.y += yPos;
addChild(menuItem);
yPos += menuItem.height + 3;
}
}
and in my MenuItem.as, everything works - I have a fancy tween when I hover over it, but when I click a menu-item, I want something to appear ofcourse. How do I know which one I clicked? I've tried with pushing everything in an array, but that didn't work out well (or maybe I'm doing it wrong). Also tried a global counter, but that's not working either because the value will always be amount of items in my XML file. Also tried e.currentTarget in my click-function, but when I trace that, all of them are "Object Sprite".. I need something so I can give each a unique "name"?
Thanks in advance!