dcsimg
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 39

Thread: Combobox controlling timeline?

  1. #1
    Junior Member
    Join Date
    Nov 2003
    Posts
    16

    Combobox controlling timeline?

    I need to know how to use the combobox component to be able to control the timeline. I have very little knowledge of actionscript, so the more help, the better. I have looked for tutorials on the internet, but I still have found none.

    Sean Cannon

  2. #2
    -Iron Myk- mykrob's Avatar
    Join Date
    Dec 2001
    Location
    Jackson, TN
    Posts
    1,356
    you can make the comboBox affect virtualy anything onstage depending on what is selected. Can you be more specific as to what you want done when what happens, and i'll be happy to help you..

    -myk

  3. #3
    Junior Member
    Join Date
    Nov 2003
    Posts
    16
    well, i want the combobox to go to different frames depending on the word clicked on. i'm assuming that i have to use "goto" at some point to get this effect, but i don't know. i hope that's enough information. thanks for the help, i really appreciate it.

    Sean Cannon

  4. #4
    Junior Member
    Join Date
    Nov 2003
    Posts
    16
    *bump*

  5. #5
    -Iron Myk- mykrob's Avatar
    Join Date
    Dec 2001
    Location
    Jackson, TN
    Posts
    1,356
    hey-
    sorry for the wait...

    you will first need to populate the comboBox
    this can be done thru the proeprty inspector, but i prefer to do it by script. It's just easier for me to read it that way..This script should be on the main timeline, in the frame where the combobox appears

    code:

    _root.comboBox.addItem("label", "data");
    _root.comboBox.addItem("label2", "data2");
    _root.comboBox.sortItemsBy("label", "ASC");



    as you can see, adding by script is very easy. The tag that says "label" is what is actually visible in the combobox to the user. They never see the "data" part, which can be anythign you want for the purpose of scripting.. In your case, the "data" for each one will probably be a frame label name that you want each one to go to..
    the last line of script, _root.comboBox.sortItemsBy, this will sort the list by label, alphabetically. the ASC simply means to sort in ascending order. You can also use DESC if you want to sort descending, or you dont have to sort at all, you can just add the items in the order you want them to appear...

    lemme know when you have this completed, and we'll move on. My goal is to help you understand what you're doing, not just copy and paste, so lets take it a step at a time

    -myk

  6. #6
    Junior Member
    Join Date
    Nov 2003
    Posts
    16
    ok, i've got that finished, and thanks for guiding me through this. i wanted to actually learn it and understand it instead of just cut and paste.

    Sean Cannon

  7. #7
    -Iron Myk- mykrob's Avatar
    Join Date
    Dec 2001
    Location
    Jackson, TN
    Posts
    1,356
    hey-
    my response time may be a bit slow today, i'm at work and just post when time allows.

    Do you want to navigate the time line after selecting and pressing a button, or just as soon as the selected item changes?


    -myk

  8. #8
    Junior Member
    Join Date
    Nov 2003
    Posts
    16
    I just want to navigate after selecting and pressing the button. And take your time, I'm in no real hurry. Once again, I really appreciate it.

    Sean Cannon

  9. #9
    -Iron Myk- mykrob's Avatar
    Join Date
    Dec 2001
    Location
    Jackson, TN
    Posts
    1,356
    cool.

    let's add a blank selection to your combobox so that nothing is selected by default
    add this to the top of your list:
    code:

    _root.comboBox.addItem("","");


    this will need to be the first. A blank is not affected by sorting order.

    next,we'll need to set a change handler for the combobox. A change handler is just as it sounds.. a function that is called everytime the selected item is changed in your combobbox...
    the change handler is set as follows:
    code:

    _root.comboBox.setChangeHandler("functionName");



    we'll define the function in a minute...
    go ahead and make your select button as well. Let me know if you're using a component button or making your own.

    -myk

  10. #10
    -Iron Myk- mykrob's Avatar
    Join Date
    Dec 2001
    Location
    Jackson, TN
    Posts
    1,356
    PS - replace functionName with whatever you're actually gonna call the function


  11. #11
    Junior Member
    Join Date
    Nov 2003
    Posts
    16
    done and done

  12. #12
    -Iron Myk- mykrob's Avatar
    Join Date
    Dec 2001
    Location
    Jackson, TN
    Posts
    1,356
    okey dokey, now for the fun part.
    we'll create our change handler funtion.
    we'll also need to create a variable to hold the information we'll pull from our change handler function:

    code:

    var choice1;
    //this simply creates a variable named
    //choice1
    function cbUpdate() {
    _root.choice1 = _root.cmoboBox.getSelectedItem().data;
    }




    more in a moment....

  13. #13
    Junior Member
    Join Date
    Nov 2003
    Posts
    16
    I've got that, and I'm using an MX component, not making my own.

  14. #14
    -Iron Myk- mykrob's Avatar
    Join Date
    Dec 2001
    Location
    Jackson, TN
    Posts
    1,356
    do you understand the previous script okay?

    pretty straightforward, this will simply look at the item that is currently selected in the combobox, and extract its "data", sending it to the variable we've named choice1.


    now for the button, give it an instance name if you havent done that yet..

    back on the main timeline, we'll make our button do something when pressed/released
    code:

    _root.myButton.onRelease = function() {
    _root.gotoAndStop(choice1);
    }



    see what we did? If you used your frame labels as your data for each selection, then when the button is pressed it will go to the approriate frame label.
    This can easily be altered to work several different ways.

    if you need more, just lemme know.

    -myk

  15. #15
    -Iron Myk- mykrob's Avatar
    Join Date
    Dec 2001
    Location
    Jackson, TN
    Posts
    1,356
    here's a more in-depth one i made for work to help hotline reps to pull up parts lists. It uses radio buttons to make a few choices. The user choice determines how the combo boxes are populated, and finally pulls up the desired parts list.. Check out the script.

    Pretty cool stuff, the movie is only one frame..

    -myk
    Attached Files Attached Files

  16. #16
    Junior Member
    Join Date
    Nov 2003
    Posts
    16
    wait a minute, i don't know what i was thinking. i just wanted it to navigate when the selected item changes. i'm so sorry.

  17. #17
    -Iron Myk- mykrob's Avatar
    Join Date
    Dec 2001
    Location
    Jackson, TN
    Posts
    1,356
    no problem, just a small script change.

    Get rid of the button script and edit your changehandler. We wont even need the choice1 variable outside the function anymore

    code:

    function cbUpdate() {
    choice = _root.comboBox.getSelectedItem().data;
    //choice is now inside the function
    _root.gotoAndPlay(choice);
    }



    same concept, we just use gotoandPlay inside the changehandler now..

    -myk

  18. #18
    -Iron Myk- mykrob's Avatar
    Join Date
    Dec 2001
    Location
    Jackson, TN
    Posts
    1,356
    is everything working for ya?

  19. #19
    Junior Member
    Join Date
    Nov 2003
    Posts
    16
    no actually, i may have missed something. here is what i have.

    function cbUpdate() {
    choice = _root.comboBox.getSelectedItem().data;
    _root.gotoAndPlay(change);
    }
    _root.comboBox.setChangeHandler("change");

    _root.comboBox.addItem("", "");
    _root.comboBox.addItem("Office Locations", "Office");
    _root.comboBox.addItem("ATM Locations", "ATM");
    _root.comboBox.addItem("Conditions Statement", "Conditions");
    _root.comboBox.addItem("Privacy Rights", "Privacy");
    _root.comboBox.addItem("YesBanking News", "latest");
    _root.comboBox.addItem("Customer Identification", "ID");
    _root.comboBox.addItem("Contact Us", "contact");
    _root.comboBox.addItem("Home", "home");

    please help me figure out where i went wrong or what i'm missing.

    sean cannon

  20. #20
    -Iron Myk- mykrob's Avatar
    Join Date
    Dec 2001
    Location
    Jackson, TN
    Posts
    1,356
    looks okay on first glance. Are your items loading into the combobox?
    Let's add a trace to the change handler function to see if the information is getting passed properly:

    code:

    function cbUpdate() {
    choice = _root.comboBox.getSelectedItem().data;
    trace("Choice = " + choice);
    }


    when the movie is tested, each time you chagne your choice, an output window showing your current selection.. If this doesnt work, please attach your FLA and i'll take a look-see..

    -myk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center