AS2 - How to target radio group data in dynamic movieClip?

I have a radioGroup nested inside a dynamic mc called (for example “bond01”)
The radioGroup is inside a mc with the property name “atod”.

I call the movieClip using

var q:MovieClip = attachMovie("bond01","question",_root.getNextHighestLevel(),{});

Then I try to reference the radioGroup by:

var rbListener:Object = new Object(); 
rbListener.click = function(evt_obj:Object) { 
   trace("The selected radio instance is " + evt_obj.target.selection.data); 
}; 
_root.question.atod.radioGroup.addEventListener("click",rbListener);

BUT all the trace gives is undefined.

I have also tried:

_root.q.atod.radioGroup.addEventListener("click",rbListener);

No luck

I tried

_root[question][atod].radioGroup.addEventListener("click",rbListener);

No luck

Can anyone tell me how it’s done?

Not looking too closely, but I noticed after the first bit of code you said it traces undefined, but then after that you’re playing with the addEventListener code. If you’re getting traces at all, doesn’t that mean your addEventListener code was tight the first time?

Sorry, I’m afraid I explained badly. The trace is not even firing.

The movieClip works fine with the embedded radioButtons if I place it on the stage and give it the instance name “bon01”

I can target the radioButtons using “bon01.rg.radioGroup. etc”

But if I place it on the stage dynamically the path does not work even though the attachMovie gives it the same name:

attachMovie(“bon01”, “bon01”, _root.getNextHighestDepth(),{});

Gotcha, and I see now that you’re attaching the event to the dynamically created “radioGroup” property which is added to the radio button instance container when its initialized.

Fun fact about components, they have a delayed initialization which means you won’t be able to access many of their properties or features correctly if you try do directly after an attach. This also applies to radioGroup. If you try your attach and trace your radioGroup, I’m guessing you’ll find it “undefined”.

Allow me to introduce you to the wonderful (note the sarcasm) doLater method! It lets you wait for that init step and do what you need to do with the right definitions… later. Except maybe you can’t even use that… ? How uninitialized are these things in AS2? I forget. Ok, well you can try to use doLater. I’ll look up the docs…
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00003047.html

And if that doesn’t work, just throw it in a self-cleaning onEnterFrame like so:

var q:MovieClip = attachMovie("bond01","question",getNextHighestLevel(),{});
var rbListener:Object = new Object(); 
rbListener.click = function(evt_obj:Object) { 
   trace("The selected radio instance is " + evt_obj.target.selection.data); 
}; 

onEnterFrame = function(){
   q.atod.radioGroup.addEventListener("click",rbListener);
   delete onEnterFrame;
}