Share on Google+Share on Google+

Creating Flex ActionScript Custom Component extending Button

Advertisement
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:

 

Advertisements

Advertisement

Posted on: April 12, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.