This really isn't rocket science. Suppose you have an AS3 class defined
like this:

package controls {
   import mx.controls.Alert;

   public class MyAlerts extends Alert {
     [Embed(source="../images/error.gif")]
     private static var iconError:Class;

     public static function error(msg:String,
closeHandler:Function=null):void {
       show(msg, "Error", Alert.OK, null, closeHandler, iconError);
     }
   }
}

This defines a new Alert class called MyAlerts. You name the file
MyAlerts.as and put it in the controls directory. Now you can do this:

<?xml version="1.0" encoding="utf-8"?>
<mycontrols:MyAlerts
   xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> "
   xmlns:mycontrols="controls.*">

   <mx:Script>
     <![CDATA[
       import controls.MyAlerts;

       public static function showMsg(msg:String):void {
         MyAlerts.error(msg);
       }
     ]]>
   </mx:Script>
</mycontrols:MyAlerts>

Save this bit of code in MyErrorMsg.mxml. As far as Flex is concerned
MyErrorMsg is another class that extends your MyAlerts class, so you can
now do this:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
   xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> "
   xmlns:myerror="controls.*"
   layout="absolute">

   <mx:Script>
     <![CDATA[
       import controls.MyErrorMsg;

       private function showErrorMessage():void {
         MyErrorMsg.showMsg("This is bad! Very bad!!");
       }
     ]]>
   </mx:Script>

   <mx:VBox height="300" width="400"
     borderStyle="solid"
     cornerRadius="5"
     horizontalAlign="center"
     verticalAlign="middle"
     backgroundColor="#ffffff">

     <mx:Button horizontalCenter="0" verticalCenter="0" label="Show
Error" click="showErrorMessage()"/>
   </mx:VBox>
</mx:Application>

Get it now? Flex treats all .mxml files and .as files as separate
classes, so when the base tag in an mxml file is your custom class, the
mxml file is just creating another class by extending your custom class.
You could have done this in actionscript instead of mxml for the
MyErrorMsg class:

package controls {
   import controls.MyAlerts;

   public function MyErrorMsg extends MyAlerts {
     public static function showMsg(msg:String):void {
       MyAlerts.error(msg);
     }
   }
}

In either case, the application mxml file would have been the same.

HTH,
Randy

--- In flexcoders@yahoogroups.com, "Chris Velevitch"
<[EMAIL PROTECTED]> wrote:
>
> On Dec 10, 2007 12:07 PM, Bjorn Schultheiss
> [EMAIL PROTECTED] wrote:
> > Add the -keep argument to the compiler options to see what goes on
behind
> > the scenes.
> >
> > This will give you your answer.
>
> I'm looking for something at a higher level before I go for a deep
> dive into the inner workings of the Flex compiler. Besides, the
> compiler output won't explain the concepts and philosophy behind it.
>
> Chris
> --
> Chris Velevitch
> Manager - Sydney Flash Platform Developers Group
> m: 0415 469 095
> www.flashdev.org.au
>


Reply via email to