
Welcome Guest
|
#1
|
|||
|
|||
|
Combobox controlling another Combobox
Hi there,
I'm working on a project where I need one combo box to control another. Here's by example what I need. Combo box 1 - Contains 3 States, Oregon, Florida, California If I click on Florida, in Combo box 2, I only want the 3 cities that correspond with that State to show up. So Orlando, Tampa, Miami. Whereas if I clicked a different State, then the cities in that State would show up in the 2nd. Can anyone help? |
|
#2
|
||||
|
||||
Actionscript:
import mx.controls.ComboBox;
// Create the combo boxes
var cb1:ComboBox = createClassObject (ComboBox, "cb1", 1);
var cb2:ComboBox = createClassObject (ComboBox, "cb2", 2);
// Position the second one so it doesn't overlap the first one
cb2.move (125, 0);
// Set the dataProvider for cb1
cb1.dataProvider = [{label:"state 1"}, {label:"state 2"}, {label:"state 3"}];
// Arrays containing the cities for a particular state
var cities1:Array = [{label:"state 1 city 1"}, {label:"state 1 city 2"}, {label:"state 1 city 3"}];
var cities2:Array = [{label:"state 2 city 1"}, {label:"state 2 city 2"}, {label:"state 2 city 3"}];
var cities3:Array = [{label:"state 3 city 1"}, {label:"state 3 city 2"}, {label:"state 3 city 3"}];
// Set the onState method to execute when the cb1 combo box is changed
cb1.addEventListener ("change", onState);
// The method executed when cb1 is changed
function onState (event:Object):Void
{
var cb:ComboBox = event.target;
var state:String = cb.selectedItem.label;
// Sets the city combo box depending on the state picked
switch (state)
{
case "state 1" :
cb2.dataProvider = cities1;
break;
case "state 2" :
cb2.dataProvider = cities2;
break;
case "state 3" :
cb2.dataProvider = cities3;
break;
}
}
__________________
Our greatest glory is not in never falling but in rising everytime we fall. - Confucius Blog | Shared Items |
|
#3
|
|||
|
|||
|
Brilliant, thank you very much.
|
|
#4
|
|||
|
|||
|
I managed to set up the combo boxes last night with all the states/cities, it looks amazing. Now my only issue is, with this array coding setup. If I click on a specific city I'd like it to then automatically load up an external file "city1.swf" and so on for each city. How would I go about setting that up in the code?
Thank you. |
|
#5
|
||||
|
||||
|
Oh come on now, I've basically given you the format of how to mess with these things. You can add a data property to the objects in your dataProvider for your cities:
Actionscript:
// New city array
var cities1:Array = [{label:"state 1 city 1", data:"city1.swf"}, {label:"state 1 city 2", data:"city2.swf"}, {label:"state 1 city 3", data:"city3.swf"}];Then you need to set up the event listener for the city combo box: Actionscript:
// Set the onCity method to execute when the cb2 combo box is changed
cb2.addEventListener ("change", onCity);
// The method executed when cb2 is changed
function onCity (event:Object):Void
{
var cb:ComboBox = event.target;
var city:String = cb.selectedItem.label;
var swf:String = cb.selectedItem.data;
}And you do something with the swf you get from the data property. I suppose load it or something.
__________________
Our greatest glory is not in never falling but in rising everytime we fall. - Confucius Blog | Shared Items |
|
#6
|
|||
|
|||
|
Alright, I managed to make the combo boxes work and interact with one another as well as load an *.swf movie once an item was clicked on the second box.
Now what I'm doing is using similar parts of the code towards narrowing down the selection from a database. Using List_boxes. An example would be, Hockey Baseball Equipment Mariners Baseball Baseball Players Yankees Football Baseball Teams Blue Jays Each column represents a Listbox, I managed to set up the first and second Listbox so they interact with each other using the code you gave me for the combo box. The problem I'm facing is I'm trying to get the 3rd List box to interact with 2nd one so that it narrows down the search even further. Is it possible that a second "child" can interact with another "child" or do I set this up? Thank you. (I attached a zip containing the FLA) Last edited by Korgan : 03-28-2006 at 06:16 PM |
«
Previous Thread
|
Next Thread
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| remove scroll bar in combobox and combobox highlight text colour | Eugene3.1 | Flash 8 |
1 | 12-02-2008 03:11 PM |
| combobox behavior question... | Ultra | Actionscript 2.0 |
6 | 11-16-2007 02:33 AM |
| Problem exporting custom skins (ComboBox) on other frame besides 1 | karma-lab | Actionscript 2.0 Components |
2 | 08-05-2006 06:36 AM |
| comboBox - add event listeners etc | dirk | Actionscript 2.0 |
0 | 05-21-2006 12:49 PM |
| DataGrid + ComboBox -> sort problem | danabanana | Actionscript 2.0 Components |
0 | 02-23-2005 07:44 PM |




