Specifications
CHAPTER 5
108
The method argument is the function to call on the object. The args argument is an optional Array of arguments
that you can pass to that function.
The following example defers the invocation of the doSomething() method, but when it is opened, Flex passes
the Event object and the “Product Description” String in an Array to that function:
callLater(doSomething, [event, "Product Description"]);
...
function doSomething(event:Event, title:String):void {
...
}
The following example uses a call to the callLater() method to ensure that new data is added to a DataGrid
before Flex tries to put focus on the new row. Without the
callLater() method, Flex might try to focus on a cell
that does not exist and throw an error:
<?xml version="1.0"?>
<!-- layoutperformance/CallLaterAddItem.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="initData()">
<mx:Script><![CDATA[
import mx.collections.*;
private var DGArray:Array = [
{Artist:'Pavement', Album:'Slanted and Enchanted', Price:11.99},
{Artist:'Pavement', Album:'Brighten the Corners', Price:11.99}];
[Bindable]
public var initDG:ArrayCollection;
//Initialize initDG ArrayCollection variable from the Array.
public function initData():void {
initDG=new ArrayCollection(DGArray);
}
public function addNewItem():void {
var o:Object;
o = {Artist:'Pavement', Album:'Nipped and Tucked', Price:11.99};
initDG.addItem(o);
callLater(focusNewRow);
}
public function focusNewRow():void {
myGrid.editedItemPosition = {
columnIndex:0,rowIndex:myGrid.dataProvider.length-1
};
}
]]></mx:Script>










