LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 


  #1  
Old 03-15-2006, 04:54 PM
Korgan Korgan is offline
Registered User
 
Join Date: Mar 2006
Posts: 8
Rep Power: 0
Korgan is on a distinguished road
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?
Reply With Quote
  #2  
Old 03-15-2006, 09:26 PM
Scottae's Avatar
Scottae Scottae is offline
God Moderator
 
Join Date: Oct 2003
Location: United States
Posts: 6,532
Rep Power: 16
Scottae is on a distinguished road
Source Example code

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
Reply With Quote
  #3  
Old 03-15-2006, 09:31 PM
Korgan Korgan is offline
Registered User
 
Join Date: Mar 2006
Posts: 8
Rep Power: 0
Korgan is on a distinguished road
Brilliant, thank you very much.
Reply With Quote
  #4  
Old 03-16-2006, 08:33 PM
Korgan Korgan is offline
Registered User
 
Join Date: Mar 2006
Posts: 8
Rep Power: 0
Korgan is on a distinguished road
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.
Reply With Quote
  #5  
Old 03-16-2006, 09:07 PM
Scottae's Avatar
Scottae Scottae is offline
God Moderator
 
Join Date: Oct 2003
Location: United States
Posts: 6,532
Rep Power: 16
Scottae is on a distinguished road
newbie

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
Reply With Quote
  #6  
Old 03-16-2006, 11:43 PM
Korgan Korgan is offline
Registered User
 
Join Date: Mar 2006
Posts: 8
Rep Power: 0
Korgan is on a distinguished road
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
Reply With Quote


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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




All times are GMT. The time now is 07:22 PM.