Flex‎ > ‎

Flex - Custom Components

In order to build a new component you should simply create a new mxml file.

For example, lets assume I created the file : guy/MyComponent.mxml

In the file I write the following
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="library://ns.adobe.com/flex/mx"
           xmlns:fx="http://ns.adobe.com/mxml/2009">
   
    <fx:Script>
        <![CDATA[
            [Bindable]
            public var button1Label:String
        ]]>
    </fx:Script>
   
    <mx:Button label="{button1Label}"/>   
</mx:Canvas>


Note that I also defined a parameter that I can initialize in the component

now, in order to use this component in my Main, I add xmlns at the root like this :

 xmlns:guy="guy.*"


and I add it like this

<guy:MyComponent button1Label="myLabel"/>


If I use Flash Builder 4 - I even get auto-complete on my new component
Comments