Creating Flex ActionScript Custom Component extending Button


 

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.

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/>

0

 

</mx:Application>

 

1

Running the example renders output as below:

 

2

Ads