How to use AS3 class in MXML?

How to use the following AS3 class in 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 suppose you can 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 that?

<mtm:TestClass></mtm:TestClass>

I am new to Flex and MXML, but not new to AS3. Thank!

+3
source share
2 answers

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

LiveDocs. MXML/AS3: http://livedocs.adobe.com/flex/3/html/help.html?content=intro_3.html

+3

, .

, , ; - Application.

, , , , .

? UIComponent; , ; wwont Flex Component LifeCycle, createChildren(), commitProperties() updateDisplayList(), , , Flex.

+3

Source: https://habr.com/ru/post/1749441/


All Articles