My problem is the following:
I have a menu made up of MovieClips containing a dynamic text box (text_txt) and a basic background rectangle.
I've assigned each item, defined by instance names (item1_mc, etc) an event listener for MouseEvent.CLICK by putting all item names into an array, and looping through it.
var menuItemsArray:Array = [item1, item2, item3, item4, item5, item6, item7, item8, item9, item10, item11, item12];
for(var i:int = 0; i < menuItemsArray.length; i++){
menuItemsArray[i].text_txt.text = labelArray[i];
menuItemsArray[i].addEventListener(MouseEvent.CLICK, menuItem_click);
}
...and then determine which is being pressed (and strip the text out of it) by using:
function menuItem_click(e:MouseEvent){
unit_name = e.target.text;
}
... and everything works fine if I click directly on the TextField within the MovieClip (returns the text), but if I click on the rim of the MovieClip (and outside the area of the dynamic text box) it just returns Error #2007 because it attempted to pull text from the [object menuItem_button_23] which contains no text.
What ideally I want to happen is that regardless of where I click on the MovieClip 'button', I get the text pulled, but I've tried things including e.currentTarget, e.target, and a combination of both along with .text, .text_txt.text, etc -- but everything ends with the same issue of having a 'dead' zone along the outside.
Furthermore, essentially what I'm trying to do is create a menu of MovieClip 'buttons' which are labeled (via the internal text field) by an array containing the label text. Then, when I click the button I want to determine which is pressed, and retrieve the label to allow me to access further information in relation to said label text.
If anyone has a solution, or a better way of what I'm trying to do I'm all ears. Should note my AS3 experience/knowledge is average at best, and I'd love to learn some new techniques to accomplish what I'm trying to do. I can also provide more information if needed.
Thanks!