Reputation: 11782
Hi guys i have a list control in a component mxml file. I have created a function in main mxml file, i want to input a text string and add it to this list. How can i do that. Currently using this code
public function add(event:MouseEvent):void
{
var name:String = mytextinputid.text;
currentState = 'ChatScreen';
mylist.____
}
Note that this function is in main and the mylist list control is in component mxml
Best regards
Upvotes: 0
Views: 4713
Reputation: 19862
If you have assigned an id to your component, which I assume is mylist, you simply call
myList.dataProvider.addItem(name);
You should always have a dataProvider
set to myList. Or else you can set one at run time.
var myCollection:ArrayCollection = new ArrayCollection();
myCollection.addItem(name);
myList.dataProvider = myCollection;
OR you can specify a dataProvider
from MXML
<mx:List id="myList" dataProvider="{myCollection}"/>
Upvotes: 1