Flash Advisor logo
:: Desktop Shortcut
:: Flash Help
Advice from Experts

Closed Thread
Results 1 to 4 of 4

Thread: two comboboxes

  1. #1

    Default two comboboxes

    Hi - could anyone help me with some code ?

    I need two comboboxes.. .

    One has a choice of 10 flavours, the other has a choice of 5 tubs

    Once the user presses a GO button the seletced choice combination determines the web page, is there a simple peice of script I can use to make this happen ?

    Thanks
    Andy

  2. # ADS
    Join Date
    Always
    Posts
    Many
     
  3. #2
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    I don't have much time to explain in detail, so I will show you a code sample of a previous project I created that employs 2 combobox components to make a selection. If you place two combobox's on the stage in a test movie with instance names of "c1" and "c2" and paste this code onto the first keyframe of the main timeline, it should give you an idea of where to proceed and how to adapt the code to your individual project...

    Code:
    //arrays are extremely useful so lets get used to using them to store data...
    //in this case, the names of the movies we want to load...
    myMovies = ["movie1.swf", "movie2.swf", "movie3.swf", "movie4.swf", "movie5.swf"];
    //create a listener object
    LO = new Object();
    //assign a value to a variable for each cbox using the change class
    LO.change = function(EO) {
    	c1Value = c1.getSelectedItem().label;
    	c2Value = c2.getSelectedItem().label;
    	//call the checkValue function 
    	checkValue();
    }
    function c1Init() {
    	c1.addItem({data:0, label:"Home"});
    	c1.addItem({data:1, label:"Info"});
    	c1.addItem({data:2, label:"Contact"});
    	c1Value = c1.getSelectedItem().label;
    	c2.addItem({data:0, label:"Make a Selection"});
    	c2.addItem({data:1, label:"Home Label2"});
    	c2.addItem({data:2, label:"Home Label3"});
    }
    c1Init();
    checkValue();
    //standard function using a switch statement to
    //check the value of a userChoice1 variable and 
    //power the project...replace trace statements with
    //whatever functionality you want
    function checkValue() {
    	userChoice1 = c1Value;
    	userChoice2 = c2Value;
    	switch (userChoice1) {
    	case "Home" :
    		//clear cbox2
    		c2.removeAll();
    		//set home labels for cbox 2
    		c2.addItem({data:0, label:"Make a Selection"});
    		c2.addItem({data:1, label:"Home Label2"});
    		c2.addItem({data:2, label:"Home Label3"});
    		break;
    	case "Info" :
    		//clear cbox2
    		c2.removeAll();
    		//set info labels for cbox 2
    		c2.addItem({data:0, label:"Make a Selection"});
    		c2.addItem({data:1, label:"Info Label2"});
    		c2.addItem({data:2, label:"Info Label3"});
    		break;
    	case "Contact" :
    		//clear cbox2
    		c2.removeAll();
    		//set contact labels for cbox 2
    		c2.addItem({data:0, label:"Make a Selection"});
    		c2.addItem({data:1, label:"Contact Label2"});
    		c2.addItem({data:2, label:"Contact Label3"});
    		break;
    	default :
    		//trace("Invalid Selection");
    		break;
    	}
    	switch (userChoice2) {
    	case "Home Label2" :
    		trace("Load movie A");
    		myMC.loadMovie(myMovies[0]);
    		break;
    	case "Home Label3" :
    		trace("Load movie B");
    		myMC.loadMovie(myMovies[1]);
    		break;
    	case "Info Label2" :
    		trace("Load movie C");
    		myMC.loadMovie(myMovies[2]);
    		break;
    	case "Info Label3" :
    		trace("Load movie D");
    		myMC.loadMovie(myMovies[3]);
    		break;
    	case "Contact Label2" :
    		trace("Load movie E");
    		myMC.loadMovie(myMovies[4]);
    		break;
    	case "Contact Label3" :
    		trace("Load movie F");
    		myMC.loadMovie(myMovies[5]);
    		break;
    	default :
    		//trace("Invalid Selection");
    		break;
    	}
    }
    //using a simple for loop to assign the listener object to both combobox's
    //you can write a lister for each component but it's not really necessary
    //for this situation...
    for (i=1; i<3; ++i) {
    	_root["c"+i].addEventListener("change", LO);
    }
    The above is designed to load movies depending on the users choice selection from two different comboboxes. While similar to your description, it is not exact and will need some fine tuning to be applied to your situation. The content for the comboboxes are all coded in AS and are not author time labels but this is just semantics and will work either way.

    hope it helps
    Regards
    NTD
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

  4. #3

    Default

    Thanks NTD thats perfect, I will paste this code and then try to tailor it to my individual situation, although a totalscript newbie I'm sure I can figure it out, but thanks really , I tried loads of Forums and no one had a clue!

    back Soon!

  5. #4

    Default

    Hi NTD

    I pasted that code in and there are no syntax errors coming up, but the 2nd box selections dont change at all according the 1st box selection, it just stays with the "home" selection labels. Any Ideas why it might not be doing so?

    thanks

    Andy

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Sponsors
Create Speaking Characters for your website and Flash movies. 15 Day Free Trial