Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using strings to go to other scenes

Guest
Mar 23, 2014 Mar 23, 2014

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?

TOPICS
ActionScript
582
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 23, 2014 Mar 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

...
Translate
Community Expert ,
Mar 23, 2014 Mar 23, 2014

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

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

likewise for your 'else if' branch.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 23, 2014 Mar 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 23, 2014 Mar 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

  }

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 23, 2014 Mar 23, 2014

I ran a trace on the text field, and the output is returning "undefined undefined"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 23, 2014 Mar 23, 2014

then you don't have a correct reference to your textfield.

to find the correct reference, on the timeline that contains your textfield, put:

trace(this+" "+cheat);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 24, 2014 Mar 24, 2014

I found the problem, I had given the text field a variable name, which was preventing it from working properly - when i removed it, it started working fine

thanks for the help

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2014 Mar 24, 2014
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines