4 Replies Latest reply on May 5, 2009 11:48 AM by Gregory Lafrance

    Inheritence in MXML components

    stevoad Level 1



      I'm creating a new project which contains several components that will share some common functionality (resizing, reordering of items etc). Is it possible to create MXML components that inherit from a base class, which contains the common functionality. This way I can still use design view to layout out my components and apply CSS styles, but share the functionality across components.





        • 1. Re: Inheritence in MXML components
          Srirangan Level 2

          Yes, inheritence is supporting in ActionScript 3. You can extend from a base class as well as implement an interface just as you could in Java.

          • 2. Re: Inheritence in MXML components
            ATIF FAROOQ Level 3


               you can  extend your component from mx.core.UIComponent class

            as it is  the base class for all visual components, both interactive and


            • 3. Re: Inheritence in MXML components
              _Natasha_ Level 4

              Hi Stephen,

              of couse you can.

              Select command to create new MXML Compopent an choose your base component from list in "based on". Your class will be there if component extends UIComponent. If it's not you can also create a component based on it (create component based on Canvas, add your component there, copy all attributes from Canvas to your component and delete root Canvas element) and implement IUIComponent interface youself (add implements attribute).

              • 4. Re: Inheritence in MXML components
                Gregory Lafrance Level 6

                When you create custom MXML components, you first need to decide what to base it on. If you simply want to make changes to a ComboBox, then your root tag will be ComboBox.


                Other times you want to combine several Flex components into one custom components. In that case you want to choose a container, such as Canvas, VBox, HBox, etc.


                If you want a completely new component, you can have UIComponent as you base tag, which gives you much of the base functionality of Flex components, but then you can implement methods for drawing, etc.


                When implementing custom components in MXML, you can get around the fact that you can't define constructors in MXML by implementing set and get methods. So if you want to be able to pass an Array into your component when it is used:


                private var _dataArr:Array;

                public set dataArr(arr:Array):void{

                    this._dataArr = arr;



                Then when you add your component in your application:


                <comp:MyComponent dataArr="[1, 2, 3, 4, 5]"/>


                If this post helps, please mark it as such.