Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 22

Creating and extending flex 2 components
Hide thumbs Also See for FLEX 2 - CREATING AND EXTENDING COMPONENTS:
Table of Contents

Advertisement

For example, you can define a custom button component based on the Flex
the following example shows:
package myComponents
{
// intro/myComponents/MyButton.as
import mx.controls.Button;
public class MyButton extends Button {
// Define the constructor.
public function MyButton() {
// Call the constructor in the superclass.
super();
// Set the label property to "Submit".
label="Submit";
}
}
}
In this example, you write your MyButton class to the MyButton.as file.
You must define your custom components within an ActionScript package. The package
reflects the directory location of your component in the directory structure of your
application. Typically, you put custom ActionScript components in directories that are in the
ActionScript classpath, subdirectories of your application, or for Flex Data Services, in the
WEB-INF/flex/user_classes directory. In this example, the
the MyButton.as file is in the myComponents subdirectory of your Flex application.
In the MXML file that references the custom component, you define the namespace and
reference it in an MXML file as the following example shows:
<?xml version="1.0"?>
<!-- MyApplicationASComponent.mxml -->
<!-- Include the namespace definition for your custom components. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<!-- Use the filename as the MXML tag name. -->
<MyComp:MyButton/>
</mx:Application>
In this example, you first define the
custom component in the application's directory structure. You then reference the component
as an MXML tag using the namespace prefix.
For more information, see
on page
121.
22
Creating Flex Components
namespace that specifies the location of your
MyComp
Chapter 9, "Creating Simple Visual Components in ActionScript,"
Button
statement specifies that
package
class, as

Advertisement

Table of Contents
loading

Table of Contents