AS3 Current Scene name for if else statement?
-
09-06-2021 - |
Question
I'm building a quick flash presentation, navigating with the up and down arrows but need to create an if else statement using the current scene's name.
I have 10 scenes named 01 - 10 but from 7 to 10 are only accessible by from a hidden button and need to find a way to loop the navigate from 01- 06 using the scene name for example:
if scene name = 04 {
go to nextScene();
} else if scene name = 05 {
go to nextScene();
} else if scene name = 06 {
go to scene 02
}
I have all working apart from the if else statement as it goes to next scene with the up arrow but continues up to 10 when I need to go to 6 and start again.
Any help would be great?
Thanks,
Thomas.
Solution
create a couple of functions, use one for your key handler and the other for the hidden button like:
function standardScenes(sceneName)
{
switch(sceneName)
{
case 01:
gotoAndPlay(sceneName);
break;
case 02:
gotoAndPlay(sceneName);
break;
case 03:
gotoAndPlay(sceneName);
break;
case 04:
gotoAndPlay(sceneName);
break;
case 05:
gotoAndPlay(sceneName);
break;
case 06:
gotoAndPlay(sceneName);
break;
}
}
function hiddenScenes(sceneName)
{
switch(sceneName)
{
case 07:
gotoAndPlay(sceneName);
break;
case 08:
gotoAndPlay(sceneName);
break;
case 09:
gotoAndPlay(sceneName);
break;
case 10:
gotoAndPlay(sceneName);
break;
}
}
OTHER TIPS
You can use this code..
stop();
import flash.events.Event;
var no:Number = 0;
btn_up.addEventListener(MouseEvent.CLICK, up);
function up(e:MouseEvent){
no = no + 1;
getScene(no);
}
btn_down.addEventListener(MouseEvent.CLICK, down);
function down(e:MouseEvent){
no = no - 1;
getScene(no);
}
function getScene(num:Number){
if(no <= 0){
no = 0;
}
if(no == 1){
gotoAndStop(1,"Scene " + no);
}
if(no == 2){
gotoAndStop(1,"Scene " + no);
}
//continue here...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow