Copy link to clipboard
Copied
I cant see whats wrong with this piece of ActionScript 3, its probably something really obvious...
function fl_SubmitConsoleButton(event:MouseEvent):void
{
var Command:String = consolecommand_txt.text;
switch (Command){
case "one" :
gotoAndStop(1);
break;
case "two" :
trace("Two has been executed");
break;
case "three" :
trace("Three has been executed");
break;
}
}
Thanks
Copy link to clipboard
Copied
For the code shown there is nothing wrong. What problem are you having? Do you get any errors? Have you traced the Command value to see if it is what you expect?
Copy link to clipboard
Copied
I have just put a trace in and nothing is showing up in the output, I'm getting no errors at all.
Copy link to clipboard
Copied
Any Ideas?
Copy link to clipboard
Copied
Does the function execute at all? If not, do you have a button with an event listener assigned to it that calls that function?
Copy link to clipboard
Copied
Not sure whats happening but yes there is an event listener linked to the button: submitconsole_btn.addEventListener(MouseEvent.CLICK, fl_SubmitConsoleButton);
Copy link to clipboard
Copied
Show the code with your new trace for Command. Is there any text in the textfield when you test it?
Copy link to clipboard
Copied
Heres my full code, incase you can see anything that could be interfering with the code.
var Password:String = 'test';
var ToggleState:int = 1;
ConsoleButton.addEventListener(MouseEvent.CLICK, fl_ToggleConsole);
submit_btn.addEventListener(MouseEvent.CLICK, fl_SubmitButton);
submitconsole_btn.addEventListener(MouseEvent.CLICK, fl_SubmitConsoleButton);
function fl_ToggleConsole(event:MouseEvent):void
{
if(ToggleState == 1){
password_txt.x = 39.90;
password_txt.y = -36.60;
submit_btn.x = 112.40;
submit_btn.y = -37.00;
console_txt.x = 39.90;
console_txt.y = -249.20;
consolecommand_txt.x = 40.10;
consolecommand_txt.y = -94.45;
submitconsole_btn.x = 381.50;
submitconsole_btn.y = -94.40;
ToggleState = 0;
}else if(ToggleState == 0){
password_txt.x = 39.90;
password_txt.y = 3.00;
submit_btn.x = 112.40;
submit_btn.y = 2.60;
ToggleState = 1;
}
}
function fl_SubmitButton(event:MouseEvent):void
{
if (password_txt.text == Password)
{
password_txt.x = 39.90;
password_txt.y = -36.60;
submit_btn.x = 112.40;
submit_btn.y = -37.00;
console_txt.x = 39.90;
console_txt.y = 3.80;
consolecommand_txt.x = 40.10;
consolecommand_txt.y = 158.55;
submitconsole_btn.x = 381.50;
submitconsole_btn.y = 158.60;
} else {
null;
}
}
function fl_SubmitConsoleButton(event:MouseEvent):void
{
var Command:String = consolecommand_txt.text;
switch (Command){
case "one" :
break;
case "two" :
trace("Two has been executed");
break;
case "three" :
trace("Three has been executed");
break;
}
}
Copy link to clipboard
Copied
I don't see the trace...
function fl_SubmitConsoleButton(event:MouseEvent):void
{
var Command:String = consolecommand_txt.text;
trace("Command is: ", Command);
switch (Command){
case "one" :
break;
case "two" :
trace("Two has been executed");
break;
case "three" :
trace("Three has been executed");
break;
}
}
If the trace never happens when you click the button then the disconnect is between the button code and the function. IF the trace does show up then the problem is likely something to do with the value in the textfield. Sometimes textfields will have extra characters you don't intend them to, which could cause the condition tests to fail. Your switch should have a default response at the end for those times when the button is clicked but a wrong value is encountered.
Copy link to clipboard
Copied
Have just tested your code and there is nothing in output. So I guess its the link between the button code and the function, any ideas where the error is?
Copy link to clipboard
Copied
Do you have things spread out along the timeline such that the instance of the button you apply the code to is not the same one in the frame where you interact with it?
Copy link to clipboard
Copied
I have figured most if it out, the code now works when Im testing it within flash but not when I publish it.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now