Hi flex forum,
I’m new to flex but with some experience at java and c.
I’m ahing a problem using an ArrayCollection as the DataProvider for my Advanced DataGrid.
The ArrayCollection holds a number of Objects of type Guest that i created.
When i try to display the results, the DataGrid can recognize the number of objects but the fields are all blank.
I Found this example and tryed folowing it but no go.
Any one has any suggestions for me?
Thanks in advance,
Guy.
Here is the code:
[RemoteClass]
public class Guest
{
//Class Veriables
private var name:String;
private var numOfPeople:int;
private var side:String;
private var innerSide:String;
private var category:String;
private var tableNum:int;
private var apArrivel:Boolean;
public function Guest(name:String, numOfPeople:int, side:String, iSide:String, category:String)
{
this.SetName(name);
this.SetNumOfPeople(numOfPeople);
this.SetSide(side);
this.SetInnerSide(iSide);
this.SetCategory(category);
//this.SetTableNum(tableNum);
//this.apArrivel = apAr;
}........
// The mxml that contains the ArrayCollection and the DataGrid
<mx:Script>
<![CDATA[
import Data.Guest;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.managers.PopUpManager;
[Bindable]
private var guestsA:ArrayCollection;
private var guest:Guest;
private var popAddGuest:AddGuestForm;
private static const ADD_TASK:String = "Click to Add Task";
//Init the ArrayCollection with the given data
private function init():void
{
guestsA = new ArrayCollection();
guestsA.addItem(new Guest("baba",3,"bride","father","family"));
guestsA.addItem(new Guest("gala",3,"groom","father","family"));
guestsA.addItem(new Guest("shala",3,"groom","mother","friend"));
guestsA.addItem(new Guest("fala",3,"groom","father","family"));
//guestsA.addItem({title: ADD_TASK});
}
//Create popup window to add guest
public function addGuest():void
{
popAddGuest = AddGuestForm(PopUpManager.createPopUp(this,AddGuestForm,true));
PopUpManager.centerPopUp(popAddGuest);
popAddGuest.submitButton.addEventListener(MouseEvent.CLICK, submitData);
}
//Gets all the details from the user and add the new guest to guestsA
private function submitData(event:Event):void
{
guest = new Guest(popAddGuest.fullName.text,popAddGuest.numOfGuests.value,popAddGuest.Side.selectedValue.toString(),
popAddGuest.InnerSide.selectedValue.toString(),popAddGuest.Category.selectedValue.toString());
this.guestsA.addItem(guest);
PopUpManager.removePopUp(popAddGuest);
Alert.show("Guest "+guest.GetName() +" was added");
}
]]>
</mx:Script>
<mx:ArrayCollection id="blankArray1">
</mx:ArrayCollection>
<mx:TitleWindow width="500" height="500" horizontalAlign="center" verticalAlign="middle" title="Guests List"
fontSize="12" x="230" y="20">
<mx:AdvancedDataGrid id="adg" width="100%" height="100%"
dragEnabled="true" dragMoveEnabled="true" >
<mx:dataProvider>
<mx:GroupingCollection id="gc" source="{this.guestsA}">
<mx:Grouping>
<mx:GroupingField name="side"/>
</mx:Grouping>
</mx:GroupingCollection>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="name" headerText="Name" editable="false"/>
<mx:AdvancedDataGridColumn dataField="numOfPeople" headerText="Number of People" editable="false"/>
</mx:columns>
</mx:AdvancedDataGrid>
<mx:AdvancedDataGrid id="blankdg" width="100%" height="100%" dataProvider="{blankArray1}" editable="true" dropEnabled="true"/>
<mx:Button id="addNew" label="Add Guest" click="addGuest()"/>
</mx:TitleWindow>
</mx:Application>