Skip to main content
March 23, 2014
Answered

Using strings to go to other scenes

  • March 23, 2014
  • 1 reply
  • 660 views

Hi, I'm having a bit of a problem:

I'm trying to use an input text field as a cheat code input to move between 2 different scenes - if the code is correct, I want to go to one scene, but if the code is not correct, I want to go to a different scene. At the moment, no matter what I put into the text field, I end up going to the scene that's supposed to be for incorrect codes - even when I enter the correct code.

The code I'm using:

stop();

//stops on this scene

{

var cheat:String = "Enter Code Here";

//declaring a variable for a cheat code

_root.cheatBox.cheat = cheat;

//sets the text of the cheat box to cheat

_root.menuButton.onRelease = function()

//when the menu button is released

{

  gotoAndStop("Menu", 1);

  //goes to menu scene and stops on that scene

}

_root.cheatBox.goButton.onRelease = function()

//when the go button in the cheat box is released

{

  if(_root.cheatBox.cheat == "N0496151")

  //if the text box contains the code

  {

   gotoAndStop("Cheat", 1);

   //goes to the cheat scene and stops on that scene

  }

  else if(_root.cheatBoxcheat != "N0496151")

  //otherwise

  {

   gotoAndStop("Menu", 1);

   //goes to the menu scene and stops on that scene

  }

}

}

All of this code is on the main timeline, is there something I'm not doing right?

This topic has been closed for replies.
Correct answer kglad

use the trace function to debug,

_root.cheatBox.goButton.onRelease = function()

//when the go button in the cheat box is released

{

trace(_root.cheatBox.cheat.text+" "+_root.cheatBox.cheat.text.length);

  if(_root.cheatBox.cheat.text == "N0496151")

  //if the text box contains the code

  {

   gotoAndStop("Cheat", 1);

   //goes to the cheat scene and stops on that scene

  }

  else if(_root.cheatBox.cheat.text != "N0496151")

  //otherwise

  {

   gotoAndStop("Menu", 1);

   //goes to the menu scene and stops on that scene

  }

}

}

1 reply

kglad
Community Expert
Community Expert
March 23, 2014

if _root.cheatBox is your textfield, you should be using

if(_root.cheatBox.text=="N0496151")

likewise for your 'else if' branch.

March 23, 2014

no, the _root.cheatBox.cheat is the text field, _root.cheatBox is just a movie clip containing it

I tried adding the .text to the end of the _root.cheatBox.cheat - however this doesn't seem to change anything

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
March 23, 2014

use the trace function to debug,

_root.cheatBox.goButton.onRelease = function()

//when the go button in the cheat box is released

{

trace(_root.cheatBox.cheat.text+" "+_root.cheatBox.cheat.text.length);

  if(_root.cheatBox.cheat.text == "N0496151")

  //if the text box contains the code

  {

   gotoAndStop("Cheat", 1);

   //goes to the cheat scene and stops on that scene

  }

  else if(_root.cheatBox.cheat.text != "N0496151")

  //otherwise

  {

   gotoAndStop("Menu", 1);

   //goes to the menu scene and stops on that scene

  }

}

}