•  
  •  

Creating your own Flex component

Adobe Flex is composed of two distinct pieces; a set of pre-built components known as the client-side framework, and a set of runtime services that allow Flex applications to integrate with back-end systems. The client-side framework is a series of ActionScript class that you utilize in MXML or ActionScript. Did you know that you can create your own ActionScript classes and reference them the same way? Remember, MXML is just short-hand notation for ActionScript.

Start by creating an ActionScript class that extends the Flex Panel component.
compClassXPanel.as

// Import the client-side framework components needed
// The .* is a wildcard that will only import classes that are needed.
import mx.containers.*;
class compClassXPanel extends Panel
{
public function compClassXPanel() {}
public function init():void {}
}

Next, create a component that uses this class as it’s root node:
myComponent.mxml

<?xml version="1.0" encoding="utf-8"?>
<compClassXPanel xmlns="*" width="400" height="400">
</compClassXPanel>

Finally, create your main application that invokes your custom component:
Main.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*">
<myComponent />
</mx:Application>

Now, this is a very simple example of how you can do this. You would normally continue to build upon your extended class. The point is that your classes are really not that different from the client-side framework.

About Rob Rusher

In his role as Principal Consultant for On3, Rob leads an software development practice to help his clients build rich Internet applications for the desktop, browser, and mobile devices, and to rapidly increase their knowledge and skills to better support their organization's goals. Rob is an Adobe Certified Expert, Community Professional, and Certified Instructor. He has taught and mentored the technical teams at HP, Overstock, Paychex, SAS, the FedEx, and other Government and Fortune 100 organizations. Rob has co-authored four best-selling books on building secure, cutting-edge and rapidly developed applications using Adobe AIR, ColdFusion and Flex. He is very active in organizing and speaking at RIA, Adobe LiveCycle, mobile conferences, and user groups. In addition to growing his software consulting practice, On3, Rob has been building expertise in rich client application development on a wider variety of devices and platforms that extend the applications to change the way we all create and live.