Starting from the post "Creating template components in Flex 3 and AIR", I've added further information on how to use the IDeferredInstance interface in Flex 3.
Template components can also be created by using the deferred creation feature, which
enables Flex 3 to load only the controls that initially appear to the user who loads the application.
With this approach you can optimize startup performance because Flex 3 loads the
components and their properties only when the user requires them.
The IdeferredInstance interface defines the getInstance() method to initialize the
property when it creates an instance of the component. This method returns a value of
Object type. The MXML component that you previously created could thus become the
following:
<?xml version="1.0"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="draw();">
<mx:Script>
<![CDATA[
import mx.controls.Image;
import mx.core.UIComponent;
import mx.core.IDeferredInstance;
public var header:IDeferredInstance;
public var footer:IDeferredInstance;
// Define an Array of properties for a row of components.
[ArrayElementType("mx.core.IDeferredInstance")]
public var content:Array;
private function draw():void {
addChild(UIComponent(header.getInstance()));
for (var i:int = 0; i < content.length; i++)
{
var myHeader:UIComponent =
UIComponent(content[i].getInstance());
var myContent:UIComponent =
UIComponent(header.getInstance());
addChild(myHeader );
addChild(myContent );
}
]]>
</mx:Script>
</mx:VBox>
When you use the IdeferredInstance interface as a data type, you can send any data type
to the property. In the addChild() method, you have carried out an implicit cast by sending
the header, footer, and content properties as arguments of the UIComponent. This
casting is necessary because the addChild() method can add an object that implements
the UIComponent interface to a container.






















News, calendar, member events, public policy and visitor information.
Posted by: Antonio | March 18, 2008 at 05:54 AM
I am very surprised! Good job!
Posted by: Marc | March 24, 2008 at 03:16 PM