Copy link to clipboard
Copied
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?
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
...Copy link to clipboard
Copied
if _root.cheatBox is your textfield, you should be using
if(_root.cheatBox.text=="N0496151")
likewise for your 'else if' branch.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
}
}
}
Copy link to clipboard
Copied
I ran a trace on the text field, and the output is returning "undefined undefined"
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now