Skip to main content
January 16, 2012
Answered

Using a combobox to navigate to scenes with as3

  • January 16, 2012
  • 1 reply
  • 3846 views

I'm a novice.  I'm trying to use a combobox to navigate to different scene in my .fla.  I was able to use a conditional (if) statement which seems to work but it only allows me to use the "if" and "else if" statement once before giving an error.  i examined information on using a "switch" but haven't had any luck understanding the coding or getting it to work.  The following is the code I've wrote.  Can anyone provide me some guidance?  Thanks in advance.

cb1.addEventListener(Event.CHANGE, home_dl);

function home_dl(e:Event)

{

    if (cb1.selectedItem.label == "A - B")

    {

        gotoAndPlay(65, "a-b");

}

    else if (cb1.selectedItem.label == "C - D")

        gotoAndPlay(65, "c-d");

}

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

At a quick glance it looks like you are missing an opening curly brace following your second if()

else if (cb1.selectedItem.label == "C - D") {

Also, while it is probably just a copy/paste error, you are short one closing brace for the function

function home_dl(e:Event)

{

    if (cb1.selectedItem.label == "A - B")

    {

        gotoAndPlay(65, "a-b");

    }

    else if (cb1.selectedItem.label == "C - D") {

        gotoAndPlay(65, "c-d");

   }

}

1 reply

Ned Murphy
Ned MurphyCorrect answer
Brainiac
January 16, 2012

At a quick glance it looks like you are missing an opening curly brace following your second if()

else if (cb1.selectedItem.label == "C - D") {

Also, while it is probably just a copy/paste error, you are short one closing brace for the function

function home_dl(e:Event)

{

    if (cb1.selectedItem.label == "A - B")

    {

        gotoAndPlay(65, "a-b");

    }

    else if (cb1.selectedItem.label == "C - D") {

        gotoAndPlay(65, "c-d");

   }

}

Inspiring
April 14, 2023

I also have a comboBox question. I added one to a stage at a frame and I'm able to set a list of options, (name, value), when the Component Parameters menu appears after I click the component on the stage. I can then pulldown and select an entry when I run a test, but I'm not clear how I can receive and store the selected value.   Is there an example of how to get a value from the callback from that interaction?

 

Also, though a panel with font control is launched when the component is double clicked, it doesn't seem to address the very small font size in the pulldown values. Is there another properties menu that can set the font size for the values in the pulldown?

Inspiring
April 16, 2023

what's the combobox look like when not moused over?


That screen grab was when not moused over. Actually it's still partially transparent even when moused over.

The is the code over the square with the gradient on a 512x512 stage.

// comboBox settings
var pulldownVal:int
var tfor:TextFormat = new TextFormat();
tfor.size = 22;
cb_1.textField.setStyle("textFormat", tfor);
cb_1.setStyle("disabledTextFormat", tfor);
cb_1.dropdown.setRendererStyle("textFormat", tfor);

stop();

cb_1.addEventListener(Event.CHANGE,cb1F);
function cb1F(e:Event):void{

// the selected label is e.currentTarget.selectedItem.label

pulldownVal = e.currentTarget.selectedItem.data
trace(pulldownVal);

}