Embedding Assets - MACROMEDIA FLEX-CREATING ADVANCED COMPONENTS Manual

Creating advanced components
Table of Contents

Advertisement

To make your components reusable in MXML, you can set component properties using tag
attributes. For example, you might want to allow the user to pass a value to your component, as
the following example shows:
<MyComponent prop1="3" />
To create components that take tag attributes in MXML, you define a variable with the same
name in your class definition:
class MyComponent extends UIComponent {
var prop1:Number;
...
}
Flex automatically initializes prop1 based on the value set in the MXML tag.
You can also add metadata to the variable definition. For example, if you are using Flex Builder,
you can insert the Inspectable metadata tag to define the property as user-editable (or inspectable),
as the following example shows:
[Inspectable(defaultValue="0")]
var prop1:Number;
You might also want to generate an event when the property is modified. For example, if you use
data binding, you can broadcast an event when the property is modified so that Flex can update
anything bound to the property. The following example causes Flex to broadcast an event named
changeProp1 when the property is modified:
[ChangeEvent("changeProp1")]
var prop1:Number;
You can also instruct your component to generate an event when a getter or setter method is
called, as the following example shows:
[ChangeEvent("change")]
function get selectedDate():Date
In most cases, you set the
setter function using the
events, see
"Dispatching events" on page
For more information on using metadata, see the chapter 'Creating ActionScript Components' in
Developing Flex Applications.

Embedding assets

Some components use new skins or other graphical assets to define the look of the component. In
these cases, you must embed the assets in the component. The source of the asset can be a file
such as a JPEG or you can extract symbols from SWF files.
To embed assets that your component uses, use the
variable declaration with the
embedded asset, which you use in the class.
The following example embeds two assets, arrowImageLarge and arrowImageSmall:
[Embed(source="arrowImageLarge.jpg")]
var largeArrow:String;
[Embed(source="arrowImageSmall.jpg")]
var smallArrow:String;
14
Creating Advanced Components
event on the getter function, and dispatch the event on the
change
method. For more information on dispatching
dispatchEvent()
15.
statement. The variable then contains a reference to the
Embed
metadata keyword. You precede a
Embed

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents