I have a popup that contains a TabNavigator control. The tabs are dynamically added to the TabNavigator when the popup loads. Is there a good way to tell when one of the tabs is loaded, from the tab itself?
I have a tab that requires a service call to be made, and I don't want the service call to be made unless the user actually goes and clicks the tab to view it. I could notify the tab from the popup control itself when the TabNavigator index was changed, but that doesn't seem like a good way to go about doing it. I'm wondering if there's an event or something I could hook to that would let me know the tab needed to be rendered for the first time (from within the tab control itself). Thanks in advance!
I think I didn't quite understand the question, so I'm trying again. I think this code will address your problem.
The trick is setting the creation policy to "none" for the component. Flex will create the tab, but not the component itself.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="onCreationComplete()" layout="vertical" minWidth="955" minHeight="600">
<mx:TextArea id="log" width="100%" height="500"/>
<mx:Script>
<![CDATA[
import mx.containers.Canvas;
import mx.events.FlexEvent;
private function onCreationComplete():void{
var canv:Canvas = new Canvas();
canv.label = "One";
canv.addEventListener(FlexEvent.CREATION_COMPLETE,onCreateTab);
canv.creationPolicy="none";
tn.addChild(canv);
canv = new Canvas();
canv.label = "Two";
canv.addEventListener(FlexEvent.CREATION_COMPLETE,onCreateTab);
canv.creationPolicy="none";
tn.addChild(canv);
canv = new Canvas();
canv.label = "Three";
canv.addEventListener(FlexEvent.CREATION_COMPLETE,onCreateTab);
canv.creationPolicy="none";
tn.addChild(canv);
}
private function onCreateTab(event:Event):void{
log.text+=event.currentTarget.label+ " created for the very first time\n";
}
]]>
</mx:Script>
<mx:TabNavigator id="tn" width="500"/>
</mx:Application>