How to use AS3 class in MXML

actionscript-3apache-flexmxml

How would I use the following AS3 class within MXML?

AS3 Class:

package mtm 
{
  import flash.display.MovieClip;
  import flash.display.Shape;

  public class TestClass extends MovieClip
  {

      public function TestClass() 
      {
          var s:Shape = new Shape();
          s.graphics.beginFill(0x000000, 1);
          s.graphics.drawRect(0, 0, 60, 60);
          s.graphics.endFill();
          addChild(s);
      } 
  }
}

MXML Document:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
        <mx:Panel width="75%" height="75%" paddingTop="10" paddingLeft="10">

    </mx:Panel>
</mx:Application>

Do I need to declare my own namespace? I am assuming it is possible to do something like:

//Where 'mtm' is my own namespace
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:mtm="com.mtm.*"></mx:Application>

And then do something like this?

<mtm:TestClass></mtm:TestClass>

I'm new to Flex and MXML, but not new to AS3.
Thanks!

Best Answer

Yes, you have the right idea. Your custom xmlns is a relative url, pointing to the custom component classes, so if TestClass is in a folder called Components, you would put xmlns:mtm="components.*". Your MXML is correct.

Here is the relevant LiveDocs link. This is a good place to find MXML/AS3 information: http://livedocs.adobe.com/flex/3/html/help.html?content=intro_3.html