Jump to content
xisto Community
Sign in to follow this  
EinReaper

The List Component in Flash

Recommended Posts

Hello!I have a list component in a fla. When I click a button, I add items to the list. (using list.addItem )The problem is that every time I add new items I want to refresh the list; this means that I want to delete all items that are in the list and leave only the new ones.Is there anyway to do this using only one function?(I know that I can use list.removeItem , but that would mean I have to delete every item in the list one by one).

Edited by EinReaper (see edit history)

Share this post


Link to post
Share on other sites

Thank you.removeAll() does indeed do the trick.But now I have another problem: when I select a field from the list what's the variable that holds the data for this field? Any field has a label (the thing you see) and a data (the variable underneath).I've tried list.data (where list is the instance name for my list), but this returns 'undefined'.I have a similar situation for a ComboBox; if I use combobox.text it returns the label for the field I selected, but I don't know how to access the data.

Edited by EinReaper (see edit history)

Share this post


Link to post
Share on other sites

Thank you.removeAll() does indeed do the trick.
But now I have another problem: when I select a field from the list what's the variable that holds the data for this field? Any field has a label (the thing you see) and a data (the variable underneath).
I've tried list.data (where list is the instance name for my list), but this returns 'undefined'.
I have a similar situation for a ComboBox; if I use combobox.text it returns the label for the field I selected, but I don't know how to access the data.


i haven't mettled with the list component for some time but if I recall correctly list.data returns an array. Have you tried list.data[0]?

Share this post


Link to post
Share on other sites

I haven't tried that because I'm looking for a function that returns data for a selected item, not an item located at position i.I have found something that might help: list.selectedItem.data . The problem is that this returns the correct value for list.selectedItem.label , but it returns 'undefined' for list.selectedItem.data.I'm not sure what I'm doing wrong...Later Edit: as it turns out list.selectedItem.data was the proper function to use. The problem was that I wasn't inserting data correctly into the items.

Edited by EinReaper (see edit history)

Share this post


Link to post
Share on other sites

How are you using the addItem function call?

 

There are two ways to use it, the first is list.addItem("label","data");

The second is list.addItem({label:"label", data:"data"});

 

Both should work to all you to retrieve the data using list.selectedItem.data.

 

There is another method to add a label to the list but as far as I know, it doesn't allow you to store data with it. (list.label.push("label"), but list.data.push("data") fails)

 

Note that you can store data in an array elsewhere if desired and push to it seperately to calling addItem (or define a function which does both :)), and retrieve the data from the array by using array[list.selectedIndex]..

 

...okay I see you've fixed your error (saw the update when using preview post), but I'll leave this post here to inform anyone who might later need this!

Edited by Nabb (see edit history)

Share this post


Link to post
Share on other sites

Well, I was using the first method: list.addItem("label","data") , but for some reason it didn't work.

The second method works just fine: list.addItem({label:"label", data:"data"})

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.