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);
}