blog.ashier.com flash / flex / air development
rss rss comment

Posts Tagged ‘Flex Tips’

Deferred instantiation is a common technique used to improve Flex application start-up time and to control when and how to instantiate child components within a container when the creationPolicy is set to none.

Last week, I was able to implement this into an application we’re currently developing at work. It took me a while to figure it out but I must say, it is really handy. A ViewStack for example will allow switching from one child to another, but as the child of that container gets to be really complicated, it may highly affect your application’s performance.

Why???
If no creationPolicy is specified for a container, that container inherits its parent’s creationPolicy. If no creationPolicy is specified for the Application, it defaults to ContainerCreationPolicy.AUTO.

This is where Deferred Instantiation can save your day.

I have below a basic example of how you can implement Deferred Instantiation using createComponentFromDescriptor()

createComponentFromDescriptor allows you to create one child at a time.

Read the rest of this entry…

Tags: ,

When creating Flex components, all child components (buttons, combobox, etc..) you add are always publicly accessible. There is a way to hide this and this is by using the Metadata tag "Exclude"

Here is a common Flex Component Example:

Actionscript:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
  3.     <mx:Button x="167.5" y="146" label="Click Me" id="btn"/>
  4. </mx:Canvas>

In the example above, "btn" property is publicly accessible outside that component. For you to hide it, you must add an "Exclude" metadata tag.

Here's is an example:

Actionscript:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
  3.     <mx:Metadata>
  4.         [Exclude(name="btn", kind="property")]
  5.     </mx:Metadata>
  6.     <mx:Button x="167.5" y="146" label="Button" id="btn"/>
  7. </mx:Canvas>

Now, the "btn" property won't be accessible outside that component. will still be accessible but it won't show up in the code hinting. Thanks to Sid Maskit for pointing this out.

Sid Maskit provided ways on how to do this not using the [Exclude] metadata/

Other Exclude kinds are

[Exclude(name="direction", kind="property")]
[Exclude(name="setFocus", kind="method")]
[Exclude(name="focusIn", kind="event")]
[Exclude(name="horizontalGap", kind="style")]
[Exclude(name="focusInEffect", kind="effect")]

Resource Blog

Tags: ,