# Duplicate MC or create new instance

**URL:** <https://forum.kirupa.com/t/duplicate-mc-or-create-new-instance/292125>\
**Category:** flash\
**Created:** [July 10, 2009, 10:47am UTC](https://forum.kirupa.com/t/duplicate-mc-or-create-new-instance/292125 "2009-07-10T10:47:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![koorb](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/koorb/32/424_2.png) [@koorb](https://forum.kirupa.com/u/koorb)\
**Post date:** [July 10, 2009, 10:47am UTC](https://forum.kirupa.com/t/duplicate-mc-or-create-new-instance/292125/1 "2009-07-10T10:47:37Z")

</div>

Hi all,

it’s been a long time since I’ve posted here! Hope everyone is well.

I am in need of some advice, my AS skills dwindled away when AS 2.0 came in and I am trying to get up to speed on AS3.

I am trying to dynamically create a number of click buttons based on the content of an XML file.

So I have a MC (window\_mc) which contains a single button (more\_details\_btn). I add an event listener to send the user to a web page on click.

However. On some items I need more than 1 more\_details\_btn’s. What is the best way to duplicate this MC and assign a new click event and different text.

Below is the code I am currently using and it is causing me all sorts of problems

```auto
		
for each(var detail:XML in productXML.details) {
    var btn = new more_btn_cls();
    btn.label_txt.text = detail.@name;
    btn.x = 100;
    btn.y = 200;
    window_mc.addChild(btn);
}

```

Firstly, it wont assign btn.label.text - it says it “Cannot access a property or method of a null object reference” btn in this code traces as an object not a movieclip is that why?

The other problem is that window\_mc.addChild(btn); does nothing, yet if I take away window\_mc it does add the clips to the Stage. (I need them inside window\_mc though)

OK, I hope that made sense, and I hope someone can help. I can’t wait to get to grips with AS3 properly - I’m writing really bad code at the moment =)

Thank you!
