DIGG IT!
Published
Wednesday, January 03, 2007
at
10:19 PM
.
I am in Edmonton Canada this week working with Grant Skinner and his amazing team teaching them Flex. Today we talked a lot about MXML and AS3 Classes and when to use each. The thing is that they are 100% the same. MXML is translated into an AS3 class during the compilation process. There is really no different between MXML and AS3 Classes and they can be used interchangeably. No really! To show this I wrote a singleton in MXML. I have found this very handy for Settings Dialogs and Pop-ups where you want 1 and only 1 instance.<SettingsDialog xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
private static var singleton:SettingDialog;
public static function getInstance():SettingsDialog
{
if ( SettingsDialog.singleton )
{
return SettingsDialog.singleton;
}else{
SettingsDialog.singleton = new SettingsDialog();
return SettingsDialog.singleton;
}
}
</mx:Script>
<mx:TextInput id="name" width="100">
<mx:TextInput id="age" width="100">
<mx:TextInput id="rank" width="100">
<mx:TextInput id="serial" width="100">
<mx:ColorPicker id="uiColor" >
<SettingsDialog>
Usage:
//call popupmanager with getInstance
mx.managers.PopUpManager.addPopUp( SettingsDialog.getInstance() , basePanel , true );
Ted on Twitter - @__ted__
Ted on Adobe Groups
Ted on LinkedIn
Ted on Facebook
Ted at Adobe