Flex Custom mxml tags example

MXML files which functionalities are extended in to other mxml files are called Custom MXML components.

Flex Custom mxml tags example

Flex custom mxml tags example

     

Flex .mxml files, whose functionalities are extended in to other Flex .mxml files are called custom mxml components. Custom mxml components are also referred to as custom mxml tags in the flex .mxml files in which their functionality is imported. Here, power.mxml is the custom mxml component whose functionality is been imported and used in the project.mxml file. Now in the base directory of  project.mxmli.e., C:\My Flex Folder, a folder solar is created and inside it the power.mxml file is placed. Now the complete folder path of power.mxml, i.e., solar.*  is put in to the MyComps names space. This MyComps  names space is used inside the project.mxml file to utilize the functionality of power.mxml file.

Now inside the <mx:Script > tags of power.mxml file, an include statement calls an action script file event.as. This action script file contains two functions with names Trinity and Neo respectively. Here, Neo is the event handler function. These functions are invoked  through the open and change attributes of flex combo box control. 

project.mxml

<?xml version="1.0"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
  xmlns:MyComps = 
'solar.*' backgroundColor = '#CCFFFC'>

<MyComps:power/>

</mx:Application>

basedirectory

 

 

 

 

  

 

power.mxml

<?xml version = '1.0' encoding = 'utf-8'?>
<mx:Box xmlns:mx = 'http://www.adobe.com/2006/mxml'>

  <mx:Script>
  include 'includes/event.as';
  </mx:Script>

  <mx:HBox>
  <mx:ComboBox open = 'Trinity()' change = 'Neo(event)'>
  <mx:String> Morpheus</mx:String>
  <mx:String> Jonathan</mx:String>
  <mx:String> Nancy</mx:String>
  </mx:ComboBox>
  <mx:TextArea id = 'crown' color = 'green'/>
  </mx:HBox>

</mx:Box>

 

 

event.as

public function Trinity():void{
crown.text = '';
}

public function Neo(eve:Event):void{
crown.text = 'Value : ' + eve.currentTarget.value + '\n' +
'Index : ' + eve.currentTarget.selectedIndex;
}

project.swf

 

 

Download the code