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

**URL:** <https://forum.kirupa.com/t/as2-how-to-target-radio-group-data-in-dynamic-movieclip/542954>\
**Category:** flash\
**Created:** [February 16, 2015, 3:37pm UTC](https://forum.kirupa.com/t/as2-how-to-target-radio-group-data-in-dynamic-movieclip/542954 "2015-02-16T15:37:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![charco57](https://avatars.discourse-cdn.com/v4/letter/c/73ab20/32.png) [@charco57](https://forum.kirupa.com/u/charco57)\
**Post date:** [February 16, 2015, 3:37pm UTC](https://forum.kirupa.com/t/as2-how-to-target-radio-group-data-in-dynamic-movieclip/542954/1 "2015-02-16T15:37:14Z")

</div>

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

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

```

Then I try to reference the radioGroup by:

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

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

```

No luck

I tried

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

```

No luck

Can anyone tell me how it’s done?

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [February 17, 2015, 12:24am UTC](https://forum.kirupa.com/t/as2-how-to-target-radio-group-data-in-dynamic-movieclip/542954/2 "2015-02-17T00:24:59Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![charco57](https://avatars.discourse-cdn.com/v4/letter/c/73ab20/32.png) [@charco57](https://forum.kirupa.com/u/charco57)\
**Post date:** [February 17, 2015, 7:10am UTC](https://forum.kirupa.com/t/as2-how-to-target-radio-group-data-in-dynamic-movieclip/542954/3 "2015-02-17T07:10:42Z")

</div>

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(),{});

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [February 17, 2015, 5:31pm UTC](https://forum.kirupa.com/t/as2-how-to-target-radio-group-data-in-dynamic-movieclip/542954/4 "2015-02-17T17:31:01Z")

</div>

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

```javascript
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;
}

```
