Skip to main content
Known Participant
July 14, 2009
Question

Unable to retrieive instance name (sometimes)

  • July 14, 2009
  • 1 reply
  • 650 views

Hello All,

I will try to state this simply.  If required I can post my code.  I have created a class that extends the MovieClip.

It is basically a retangular shape, with a color and a label that can be set via the "properties" concept.

The label.text property is public.

I create a "new"  object of this item (more or less a button) depending on reading an xml file.

If the file has 3 names (titles like "Lesson 1", Lesson 2" etc).  I create a new "button" for each name in the xml file.

so I can get 3 instances of the object on the stage.  Which I get.  I create each new object like this:

var link:linkBase;

var menu:linkBase;

I use a for loop to read the xml data, and create the instances:

for ....

menu = new linkBase();

// i try to give it an instance name like the

menu.name = xmlList.name // name = "Week1", "Week2", "Week3", etc

i push the menu object into an array like this: nav_button.push(menu), in the for loop.

I can draw the three objects on the stage.

I have a stage listener that will trace the target name if I click on the instance. I get "null" if I click off the button.

My problem is that I get the target name for only the second and third instances, and not the first.

If I comment out the menu.name line, and click each instance on the stage, I get "instance9", instance12, instance15.  So I know there are three

objects there.

I can do something like this to get a name on the first instance: nav_button[0].name = xmlList.week, or hard code a string like "Week1".

But I want to be able to do this in a loop of some sort.  I am trying to create a user friendly name for each instance, so I know

what I am clicking on, and take action depending on the name "week1", "week2" etc.

Any ideas on what I am missing in terms of naming a instance on the stage?

Thanks

eholz1

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
July 14, 2009

show your for-loop that creates you instances, assigns their instance names and adds their event listeners.  also post your listener function.

eholz1Author
Known Participant
July 14, 2009

Hello Kglad

And thanks for the offer to check the code.

I am Vglad for your response to post my code!  In going back and looking at my code, to

see what I would need to post per your request, I discovered a DUMB error on the programmer's part!!

The "programmer" is me!!!  So you solved the problem for me, without having to evaluate my code and

spotting the DUMB error!  Thus, I saved face!

These forums are helpful,

Thanks again,

eholz1 aka eric

kglad
Community Expert
Community Expert
July 14, 2009

you're welcome.