|
-
Senior Member
AS2: Question about dataProvider
I thought the point of the dataProvider method for a combobox was so that I could simply edit the array linked to a combobox and have the combobox always follow what was in the array. I seem to have to keep re-assigning the dataprovider for it to work though.
Example:
Create a single dropdown box with the ID of 'cb_prodline'
Code in frame1:
PHP Code:
var dp_prodline:Array = [];
cb_prodline.dataProvider = dp_prodline;
dp_prodline.push({label:"animal"});
dp_prodline.push({label:"vegetable"});
dp_prodline.push({label:"mineral"});
dp_prodline = [];
trace("checking labels in dp_prodline")
for (var i in dp_prodline){
trace(dp_prodline[i].label);
}
My logic would say that this combobox should be empty. The line dp_prodline=[] should have cleared it, right? The trace of the dp_prodline array is empty, but the combobox still has the three items in it. I know the tracing code works okay because if I don't empty the array, it traces fine.
If I add another
cb_prodline.dataProvider = dp_prodline;
at the end of the file, then the combobox gets emptied.
I just don't have a clue when I am supposed to redefine the dataProvider and when I don't. I didn't have to redefine it to have the items added to the list, but I did to have them erased from the list.
The inconistencies worry me that I will come across other problems down the road if I use dataProvider, but I really like the idea of dealing with an array of objects instead of a clunky combobox. I get even more worried when in the above example, anytime after the dp_prodline=[] line I can add NEW items to my dataProvider array and the combobox won't change until I re-assign it.
Can anyone shed light on this?
-
Senior Member
hmm..it seems to only be a problem for clearing out the array?
cause this seems to keep a constant 'check' on the data in the array..
both before & after you assign the data provider to the combobox.
PHP Code:
var dp_prodline:Array = [];
//cb_prodline.dataProvider = dp_prodline;
dp_prodline.push({label:"animal"}); dp_prodline.push({label:"vegetable"}); dp_prodline.push({label:"mineral"});
cb_prodline.dataProvider = dp_prodline;
dp_prodline.push({label:"animal2"}); dp_prodline.push({label:"vegetable3"}); dp_prodline.push({label:"mineral4"});
I guess just everytime you clear out the array throw in a line to clear out the CB too?
PHP Code:
dp_prodline = []; cb_prodline.removeAll();
-
FK'n_dog
whispers is correct, you must use removeAll
although your array is called dp_prodline, when the combobox
uses it as a dataProvider it constructs its own internal array -
PHP Code:
_level0.combo.__dataProvider = [object #127, class 'Array'] [
0:[object #128, class 'Object'] {
data:undefined,
label:"animal"
},
etc...
-
Senior Member
Not only does the line
dp_prodline = [];
not empty out the combobox, but it seems to break the connection between the combobox and the dataprovider.
If you define the dataprovider, add three items, clear the dataprovider, then add three different items, the combobox shows the first three items. So it not only does not clear, but no longer even seems to use the dataprovider at all. It might have something to do with the default dataprovider being [] so that when you set it back to [] flash thinks you want to remove the connection to that provider?
Not sure. the workaround is to redefine the dataprovider everytime you reset the dataprovider to []. It is a functional workaround, I was hoping someone would understand why this happens and if there is a more 'proper' way to erase the dataprovider contents without breaking that connection.
-
FK'n_dog
as per my post above
when you use removeAll you also remove the __dataProvider array
example -
PHP Code:
_level0.combo.__dataProvider = [object #127, class 'Array'] [
0:[object #128, class 'Object'] {
data:undefined,
label:"animal"
},
etc...
then use - combo.removeAll();
PHP Code:
_level0.combo.__dataProvider = [object #125, class 'Array'] []
// empties the dataProvider array
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|