# \[Flash8 AS2\] Create buttons with AS2

**URL:** <https://forum.kirupa.com/t/flash8-as2-create-buttons-with-as2/236781>\
**Category:** flash\
**Created:** [August 23, 2007, 4:39pm UTC](https://forum.kirupa.com/t/flash8-as2-create-buttons-with-as2/236781 "2007-08-23T16:39:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stela](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@Stela](https://forum.kirupa.com/u/Stela)\
**Post date:** [August 23, 2007, 4:39pm UTC](https://forum.kirupa.com/t/flash8-as2-create-buttons-with-as2/236781/1 "2007-08-23T16:39:16Z")

</div>

Hello, I got this code from a book, but cant understand why do I need the second var to create and show the buttons.  
To resume, this code creates four buttons just with AS.  
Shouldn’t just one var should be enough?  
I tried with just one var, but it just show one button, instead the four of them.  
Thanks.

var baseMovieClip:MovieClip = \_level0;  
var tempMovieClipHolder:MovieClip;  
for (var i:Number = 0; i \< 5; i++)  
{  
// Create a movie clip  
baseMovieClip.createEmptyMovieClip(“buttonClip” + i, ;  
baseMovieClip.getNextHighestDepth());  
tempMovieClipHolder = baseMovieClip[“buttonClip” + i];  
// Assign an ID to a timeline variable tied to the button  
tempMovieClipHolder.buttonID = i;  
// Draw something inside the button so it can be seen and clicked on  
tempMovieClipHolder.lineStyle(1, 0x333333);  
tempMovieClipHolder.beginFill(0x6666AA);  
tempMovieClipHolder.moveTo(0, 0);  
tempMovieClipHolder.lineTo(50, 0);  
tempMovieClipHolder.lineTo(50, 25);  
tempMovieClipHolder.lineTo(0, 25);  
tempMovieClipHolder.lineTo(0, 0);  
// Position the button  
tempMovieClipHolder.\_y = 10;  
tempMovieClipHolder.\_x = i \* 60 + 10;  
// Make the button clickable. Pass along the ID that was assigned  
// to the button’s timeline  
tempMovieClipHolder.onRelease = function()  
{  
handleButtonClick(this.buttonID);  
}  
}  
function handleButtonClick(buttonID:Number)  
{  
trace(“Clicked on button number: “ + buttonID);  
}
