PDA

View Full Version : ComboBox hell


xwielder
08-28-2007, 06:46 PM
I created a new AS3 document in Flash CS3.

I opened the "Component" window and dragged a ComboBox onto the stage.

I entered selected the ComboBox and went to the Parameters tab.

Under "dataProvider", I entered 2 separate values, assigned a "label" and a "data" for each value.

So I have now a ComboBox on my stage that has the following two attributes:

label: "Team 1" data: 23
label: "Team 2" data: 24


When I initially dragged the ComboBox onto the stage, it was classified as a MovieClip. Fine, so I gave it the instance name of "teamList_mc"


What I want to do now, is trace out the value of the selected ComboBox option when the user presses a submit button. For example; a user would choose from the ComboBox drop down menu "Team 2", then press submit. Upon pressing submit, it would trace out and display: 24
(note: I also have a MovieClip submit button that you'll notice in the below code)


Here is where I'm having issues.

// How do I get "teamList_mc" to be seen as a ComboBox?
function clickedSubmitScore(event:MouseEvent):void
{
var i:Number = teamList_mc; // of course, this does not work
trace(i);
}
submitScore_mc.addEventListener(MouseEvent.MOUSE_U P, clickedSubmitScore);


Or how about:

function clickedSubmitScore(event:MouseEvent):void
{
var myComboBox:ComboBox = new ComboBox();
teamList_mc = myComboBox.value; // <-- this is crap, doesn't work
var i:Number = teamList_mc; // <-- this is crap, doesn't work
trace(i);
}
submitScore_mc.addEventListener(MouseEvent.MOUSE_U P, clickedSubmitScore);


All my above coding attempts to pull data value from teamList_mc is a joke. I know I'm just blind as to what the answer is. Are there any sight healers out there? :P

xwielder
08-28-2007, 08:13 PM
var totalTeams:Number = 2;
var teamList:ComboBox = teamList;

for(var i:Number = 0; i < totalTeams; i++)
{
teamList.addItem({label:"Team " + (i + 1), data:(i + 1)});
};


function clickedSubmitScore(event:MouseEvent):void
{
trace(teamList.value);

}
submitScore_mc.addEventListener(MouseEvent.MOUSE_U P, clickedSubmitScore);


I basically changed "teamList_mc" to "teamList", then made "var teamList:ComboBox = teamList;"

I'm a C++ coder from the core, and am soon realizing day to day that C++ is FAR different than coding Flash CS3 AS3.
With Flash, you have to consider not only the actual AS code, but you're dealing with a "timeline" and "stage" as well.

Funky stuff. :)


Anyway, I'm just posting to say that I've figured out my original issue (see above code).

Thanks to all who viewed this post!