Hi Ned,
I need a help!
I have tried with the coding. I created three scenes:
1st scene: 5 buttons are placed;btn1,btn2,btn3,btn4,btn5 and the order is same as the numbering of buttons
2nd scene: correct page
3rd scene: error page
Now when i click on btn1, it takes me to the correct page. And, if i click on any other button nothing happens.
Below is the code:
var myArray:Array = [btn1,btn2,btn3,btn4,btn5];
var counter:int = 0;
for(var i:int=1;i<=5;i++)
{
this["btn"+i].addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene);
function fl_ClickToGoToScene(event:MouseEvent):void
{
if(myArray[counter] == event.currentTarget)
{
counter = counter+1;
MovieClip(this.root).gotoAndPlay(1, "Scene 3");
//increment the counter
//go to the correct scene
}
else if(myArray[counter] != event.currentTarget)
{
MovieClip(this.root).gotoAndPlay(1, "Scene 4");
// show an error
}
}
}
The first thing you should do is get rid of using scenes. They are only a problem waiting to happen. Either use frames of just the one timeline or use movieclips and control which is visible. You will find it alot easier to manage of you take the latter approach.
The next thing you need to do is get that function out of the loop you have it in. You only need to assign multiple listeners... the function is coded generically and only needs to be defined once.
Another thing to avoid doing is using unnecessary root references. If the code is in the main timeline, there is no need to target it using root.
For your conditional there is no need for the != test, just the else portion is needed. The first if is enough to determine whether it is true or false... if it ain't true it has to be false....
if(test==true){
} else {
}