dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: List box trouble

  1. #1
    Senior Member
    Join Date
    Jul 2000
    Posts
    131
    I'd like to use a list box but I can't figure out how to make them work.

    I need it to list various options. These options, if selected will tell target another movie. Can you do this with a list box, if so, how?

    Also, how can I change the size of the font used... it's pretty small.


  2. #2
    Senior Member
    Join Date
    Apr 2002
    Location
    Hong Kong
    Posts
    171
    Assuming that you want to do this in code then:
    Code:
    //To add an item from an array to a listbox called ExerciseFields
    ExerciseFields.addItem("movie name="+myNames[ii], ii);
    Then to react to someone clicking on an item in the list box
    Code:
    function onSelectField(thisField) {
    	var index = thisField.getSelectedIndex(); // this gives you ii from the adding code
    // now you can use it to do something to the ii movie.
    and in the instance of the listbox, in the changehandler parameter give the name of this function (ie onSelectField).

    Hope this helps.

  3. #3
    Senior Member
    Join Date
    Jul 2000
    Posts
    131
    Oh man, you're gonna have to be more basic than that.
    Where do I put that coding?

    Is there a downloadable file from someone who's already made one of these that I can look at? That would be the most simple of ways.

  4. #4
    Senior Member
    Join Date
    Apr 2002
    Location
    Hong Kong
    Posts
    171
    OK, sorry for baffling.
    There are two ways to get options listed in the box. The easiest is to write them in when you designing the movie. To do that, drag the list box from the components panel onto the stage. In the properties box, look at parameters for the component, click on the labels field and use the magnifying glass to type in what you want to see. Repeat for the data field giving each label some kind of id.

    If you don't know what data you want in the list at design time, then you have to use ActionScript to do the same thing. This you do by again putting a list box on the stage, give it an instance name (eg myList) and then put the code like this in the first frame of your movie:
    myList.addItem("Aardvark",10);
    myList.addItem("Beaver",20);
    myList.addItem("Cheetah",30); //etc

    If you run the movie, you will see the list box, but nothing will happen when you click an item. So you need a function that will do something - a change handler. Again, in the parameters for the list box type a function name in the Change Handler field (eg onSelectItem). Then in the first frame of the movie type a function definition such as:

    onSelectItem = function(component) {
    var index = component.getSelectedItem().data; // this will be 10, 20, 30 etc
    _root.gotoAndStop(index); // do something based on this data
    }

    Now, when you run the movie and click on the list, you should jump to a particular frame in your movie.

    You can change the font, but I am afraid that I don't know how Hope this is more useful

  5. #5
    Senior Member
    Join Date
    Jul 2000
    Posts
    131
    I'll give it a shot and let you know.

    thanks

  6. #6
    Senior Member
    Join Date
    Jul 2000
    Posts
    131
    I must be stupid.

    Let me see if I can give you some information from my movie and you can give me the exact code.

    I have a list of film making titles, which once clicked will show the discription of each position.

    Now, the list box is titled "list"
    The first and second selections are "Producer" and "Director." The data on those selections are "01" for producer and "02" for director.

    I'm getting mixed up with the change handler code as well as the actionscript that goes in the first frame of my movie. The labels and data I've got down.

    Please, just a little bit more help, I'm almost there. Help this whelp finish his list, will ya?

  7. #7
    Senior Member
    Join Date
    Apr 2002
    Location
    Hong Kong
    Posts
    171
    As you are putting the labels and data direct into the component at design time, forget about the code for doing it. The only code that you need on frame 1 is
    Code:
    onSelectItem = function(component) { 
    var index = list.getSelectedItem().data; // this will be 01, 02  etc 
    trace("you clicked on "+list.getSelectedItem().label); // just to prove that things are going well!
    _root.gotoAndStop(index); // do something based on this data, this assumes that the data is a frame label 
    }
    If you don't get any trace when you click on a list, make sure that the list component has onSelectItem as the name of the change handler in the parameters. If you get a trace output, but nothing happens, then maybe the data should not be "01" etc as this might not be the label of a frame, or name of a movie.
    Keep going!

  8. #8
    Senior Member
    Join Date
    Jul 2000
    Posts
    131
    Okay, at least it's going something now. Now I can figure out all the little details.

    thanks a ton!!!

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