PDA

View Full Version : Instance of a dynamic button...


James Rods
02-16-2006, 05:19 PM
Hello there,

I've got a little problem that's jamming my brain and I can't really picture what's wrong. I created a dynamic menu using a simple array, attaching all the buttons to the stage. Which button, of course, will execute a different action, and there's where the problem is. The code below was suppose to sort the whole thing out but when I click on the button nothing happens.



_root.mainMenu_0.onRelease = function(){
trace("button 1 worked");
}
_root.mainMenu_1.onRelease = function(){
trace("button 2 worked");
}

etc...


Does anyone know what's wrong? I've debugged the code and the duplicated objects (mainMenu_0, mainMenu_0, etc) are there.

Well, I'll keep frying my brain over here.
Cheers guys,

James.

peteranselmo
02-16-2006, 05:21 PM
can you post your fla?

James Rods
02-16-2006, 05:36 PM
Sure. There it is...

peteranselmo
02-16-2006, 05:49 PM
as the instance is created.. just add an onRelease to the mc..

// VARIABLES

sectionNumber = new Array("1", "2", "3", "4", "5", "6", "7", "8");
sectionCounter = sectionNumber.length;

count = 0;

// hides the original movie clip that has been attached to the Stage
_root.attachMovie("MainMenu", "mainMenu", 100, {_x:200, _y:50});
_root.mainMenu._visible = false;


//// FUNCTIONS

// function that will mount the menu on the Stage
function showMenu() {

// duplicates movie clips
if(count >= 0 && count <= (sectionCounter - 1)) {
_root.mainMenu.duplicateMovieClip("mainMenu_" + count, count);
actualItem = _root["mainMenu_" + count];
actualItem.labelName = sectionNumber[count];
var thisScope = this;
actualItem.onRelease = function() {
trace(this.labelName);
}
}

// rearranges the buttons on Stage
if(count != 0){
previousItem = _root["mainMenu_" + (count - 1)];
actualItem._y = previousItem._y + (previousItem._height + 2);
}

if(count == (sectionCounter - 1)) {
clearInterval(menuInterval);
}

count ++;
}


//// CALLS

// calls the function showMenu()
menuInterval = setInterval(showMenu, 50);

_root.mainMenu_0.onRelease = function() {
trace("button 1 worked");
}

James Rods
02-16-2006, 05:55 PM
Niiice. Thanks Dude, you saved a lot of neurones.

See you around,
James.