Home Tutorial Flex Flex-components Creating Flex ActionScript Custom Component extending Button

 
 

Creating Flex ActionScript Custom Component extending Button
Posted on: April 12, 2010 at 12:00 AM
ActionScript can be used to create custom components. In the example below, a custom button component is created by extending Button class.
Creating ActionScript components

Creating Flex ActionScript Custom Component extending Button

 

ActionScript can be used to create custom components. In the example below,  a custom button component is created by extending Button class.

 

For this, create a actionscript class ?MyCustomButton.as? in a package mycomp and extends from Button class. Here label, height and width are modified.

MyCustomButton.as

 

package mycomp

{

    import mx.controls.Button;

 

    public class MyCustomButton extends Button {  

       

        public function MyCustomButton() {            

            super();

                       

            label="My Button";

            height=30;

            width=100;             

        }

    }

}

 

 

To use this component in mxml file (CustomButtonExample.mxml), set xmlns property to the custom component like xmlns:CompRI="mycomp.*". This indicates that the prefix CompRI will be used to refer any component in mycomp package.

 

CustomButtonExample.mxml

 

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

      layout="vertical"

      xmlns:CompRI="mycomp.*">

 

    <CompRI:MyCustomButton/>

 

</mx:Application>

 

Running the example renders output as below:

 

Related Tags for Creating Flex ActionScript Custom Component extending Button:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.