I swore I wouldn't

Icon

Oh no, I'm blogging now?

Fun with the Flex component loading order


I have a Flex component that I have written that consists of a tabbed navigator that houses several panels, each panel housing a Flex datagrid.  An action in another component triggers an url to load and populate these datagrids.  The problem that I encountered was that if the datagrid had not yet been viewed, then the datagrid would not be created yet, and as such, the event listener that populates the datagrid was never fired.

The solution for this was actually quite simple.  I attached an event handler to the datagrid’s creationComplete event:


...
creationComplete="dgCreated(event);"
...

protected function dgCreated(event:FlexEvent):void {
dgEventListeners(event.target as DataGrid);
}

protected function dgEventListeners(dg:DataGrid):void {
dg.addEventListener(DataGridEvent.ITEM_EDIT_BEGINNING,setFieldToEdit);
dg.addEventListener(DataGridEvent.ITEM_EDITOR_CREATE,loadMetaDataCombo);
dg.addEventListener(DataGridEvent.ITEM_EDIT_END,onItemEditEnd);
dgLoad(dg);
}

protected function dgLoad(dg:DataGrid):void {
// code to load the actual datagrid with the appropriate data
}

There is some other code in there related to some inline editing code that I wrote, but my approach was essentially for the following to occur:

Given more time, I’ll likely convert the majority of the Flex to AS3 as I feel that the load process is much more transparent and easier to control, but for now, this is operating as intended.

Category: Client

Tagged: , ,

Leave a Reply