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

Whats wrong with this ActionScript 3?

Guest
Nov 28, 2014 Nov 28, 2014

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

TOPICS
ActionScript
384
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
LEGEND ,
Nov 28, 2014 Nov 28, 2014

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?

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
Nov 28, 2014 Nov 28, 2014

I have just put a trace in and nothing is showing up in the output, I'm getting no errors at all.

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
Nov 28, 2014 Nov 28, 2014

Any Ideas?

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
LEGEND ,
Nov 28, 2014 Nov 28, 2014

Does the function execute at all?  If not, do you have a button with an event listener assigned to it that calls that function?

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
Nov 28, 2014 Nov 28, 2014

Not sure whats happening but yes there is an event listener linked to the button: submitconsole_btn.addEventListener(MouseEvent.CLICK, fl_SubmitConsoleButton);

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
LEGEND ,
Nov 28, 2014 Nov 28, 2014

Show the code with your new trace for Command.  Is there any text in the textfield when you test it?

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
Nov 29, 2014 Nov 29, 2014

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;

  }

}

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
LEGEND ,
Nov 29, 2014 Nov 29, 2014

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.

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
Nov 29, 2014 Nov 29, 2014

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?

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
LEGEND ,
Nov 29, 2014 Nov 29, 2014

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?

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
Nov 29, 2014 Nov 29, 2014
LATEST

I have figured most if it out, the code now works when Im testing it within flash but not when I publish it.

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