What I am trying to do is have a user input his data into multiple textboxes, then once the data is entered it is displayed on the datagrid at runtime. The problem is when I run the app I click my button but no information entered is added to datagrid. My textboxes are also supposed to clear once the button is pressed but again nothing happens. Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]private var dgItems:ArrayCollection;
[Bindable]public var temp:Object;
public function addItem(evt:Event):void {
//add item if the text input fields are not empty
if(name_input.text != ""&& location_input.text !="") {
//create a temporary Object
temp = myDG.selectedItem;
var temp:Object = new Object();
//add the text from the textfields to the object
temp = {name:name_input.text, location:location_input.text};
//this will add the object to the ArrayColldection (wich is binded with the DataGrid)
dgItems.addItem(temp);
//clear the input fields
name_input.text = "";
location_input.text ="";
}
}
]]>
</mx:Script>
<mx:DataGrid x="97" y="110" dataProvider="{dgItems}" id="myDG">
<mx:columns>
<mx:DataGridColumn headerText="Column 1" dataField="name:"/>
<mx:DataGridColumn headerText="Column 2" dataField="location:"/>
</mx:columns>
</mx:DataGrid>
<mx:Button x="97" y="51" label="add" click="addItem(event)"/>
<mx:TextInput x="117" y="300" id="location_input"/>
<mx:TextInput x="117" y="340" id="name_input"/>
</mx:Application>
Any help is greatly appreciated.