# Adding a different mc each time btn is pressed

**URL:** <https://forum.kirupa.com/t/adding-a-different-mc-each-time-btn-is-pressed/633976>\
**Category:** flash\
**Created:** [November 19, 2015, 3:50pm UTC](https://forum.kirupa.com/t/adding-a-different-mc-each-time-btn-is-pressed/633976 "2015-11-19T15:50:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![iancraig](https://avatars.discourse-cdn.com/v4/letter/i/7ab992/32.png) [@iancraig](https://forum.kirupa.com/u/iancraig)\
**Post date:** [November 19, 2015, 3:50pm UTC](https://forum.kirupa.com/t/adding-a-different-mc-each-time-btn-is-pressed/633976/1 "2015-11-19T15:50:03Z")

</div>

How would I programme a button to load a new movieclip over the top of another movieclip on click, and once loaded over the top, remove the previoius one.

Each time the button is clicked a new movie clip is loaded.

Any help gratefully is much appreciated…

---

<div class="post-metadata">

**Author:** ![PEProgrammer](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@PEProgrammer](https://forum.kirupa.com/u/PEProgrammer)\
**Post date:** [November 20, 2015, 4:39am UTC](https://forum.kirupa.com/t/adding-a-different-mc-each-time-btn-is-pressed/633976/2 "2015-11-20T04:39:00Z")

</div>

Set up all of you MC’s that you want to add for export with action script under properties. Are the movie clips all the same? If you wanted to add different mc’s you can have several buttons but continue to add the movie clips to the same array.

> var xPosition:int = “Watever you want your x position of the mc to be”  
> var yPosition:int = “Watever you want your x position of the mc to be”  
> var mcArray:Array = new Array();

> //create a button on stage with an event listener with corresponding function

> btn.addEventListener(MouseEvent.CLICK, addMC)

> function addMC(event:MouseEvent):void  
> {  
> //check if a movie clip is on stage already  
> if (mcArray.length \> 0)  
> {  
> while (mcArray.length \> 0)  
> {  
> removeChildAt(mcArray[0];  
> }  
> }

> ```
> //dynamically create a new instance of the movie clip you want to use
> var newMc:yourMovieClip = new yourMovieClip;
> //give the mc its coordinates on screen
> newMc.x = xPosition;
> newMc.y = yPosition;
> //push the mc into an array
> mcArray.push(newMc);
> // add it to the screen
> addChild(newMc);
> 
> ```
> 
> }
