PDA

View Full Version : why's my switch/case not working?



zoo_buffalo
February 15th, 2007, 12:32 PM
hi guys
having a problem using the switch/case thingy in flash - i am trying to use it for navigation - setting a variable to a certain value, then the switch should check for the value i have set and then navigate to the right part of the timeline. only it's not working. here's my code:

switch (clicked) {
case "contact" :
_root.gotoAndPlay("contact");
break;
case "whoweare" :
_root.gotoAndPlay("whoweare");
break;
default :
trace("ouch");
}
i get the "ouch" trace whatever i click. i have set it up so that when the user clicks the 'contact' button the variable "clicked" is set to "contact" and same with the who we are button, sets it to "whoweare"... these are also the lables on the timeline. what i think is happening is that flash is just continuing to play the timeline as it goes to the 'contact' page always, the next thing on the timeline. would be grateful if someone could take a look at the file and tell me what i'm doing wrong...
http://myweb.tiscali.co.uk/murderkins/gv/gv05.fla
thanks!
emma.

kortexvfd
February 15th, 2007, 12:39 PM
Change on each button:
on (release) {
_root.clicked = "whoweare";
this._parent.gotoAndPlay("leavehome");
}

Change Switch:
switch (_root.clicked) {
case "contact" :
_root.gotoAndPlay("contact");
break;
case "whoweare" :
_root.gotoAndPlay("whoweare");
break;
default :
trace("ouch");
}

zoo_buffalo
February 15th, 2007, 12:53 PM
oh magic, thank you! :) wow it's really confusing where to put quotation marks and where not to... any pointers on general rules about this?

kortexvfd
February 15th, 2007, 12:58 PM
really depends on how you design it. Look into scope (lost of stuff on that) as to why you had to use _root.

You needed the quotes because you were checking for a string in your switch (i.e. you had quotes in the switch, but not in the variable you were checking for)

zoo_buffalo
February 15th, 2007, 01:14 PM
thanks for the help. i think i got it - have a bit of a block with these things! i do understand the _root thing - i had just been trying all different things and had ended up missing that too... but once again these forums save my life - thanks so much!