Skip to main content
Participant
October 2, 2009
Answered

Switch Statements - Switching on a Input Textbox

  • October 2, 2009
  • 1 reply
  • 549 views

Hello,

I have 3 input text boxes and I want to display a different part of an XML file to display (in a different textbox) depending on what input textbox has been selected.

I have achieved this by using 3 separate functions and it works fine but I want to use a switch statement within one function to achieve the same result.  So the user will click on a textbox which calls the function and switches depending on the textbox to load the text from an XML file.

I am reletively new to AS3 and Flash in general so I don't know if using a switch statment in this way is even possible to do.

Code looks like this:

var req:URLRequest = new URLRequest("Manual.xml");

var loader:URLLoader = new URLLoader();

var manual:XML;

euProduct1_txt.addEventListener(MouseEvent.CLICK, loadText);

euProduct2_txt.addEventListener(MouseEvent.CLICK, loadText);

euProduct3_txt.addEventListener(MouseEvent.CLICK, loadText);

function loadText(evt:MouseEvent):void

{

     switch(MouseEvent.CLICK)

     {

          case euProduct1_txt:

               manual = new XML(loader.data);

               external_txt.text = manual.sales_area[0].info;

               manualTitle_txt.text = manual.sales_area[0].name;

          break;

          case euProduct2_txt  etc etc....

     }

}

loader.addEventListener(Event.COMPLETE, loadText);

loader.load(req);

The parts I'm struggling with are what goes in the switch condition and each case statement.

Thanks

This topic has been closed for replies.
Correct answer Ned Murphy

For what are showing, you will want to switch based on:  evt.currentTarget.name

function loadText(evt:MouseEvent):void

{

     switch(evt.currentTarget.name)

     {

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
October 2, 2009

For what are showing, you will want to switch based on:  evt.currentTarget.name

function loadText(evt:MouseEvent):void

{

     switch(evt.currentTarget.name)

     {

Participant
October 2, 2009

Yeah that worked perfectly....many thanks Ned

Ned Murphy
Legend
October 2, 2009

You're welcome