Macromedia flex builder-using flex builder User Manual

Page of 158
124
Chapter 5:  Working with Components
Creating a component from an existing component
You can create a new component from any component in an existing MXML file. Flex Builder 
creates the new component file based on the component you select.
To create a component file from a component in an existing MXML file:
1.
In Flex Builder, open an MXML file containing the component you want to use.
2.
Do one of the following:
If working in Design view, select and right-click the standard component you want as the 
basis of your new custom component and then select Create Local Component from the 
context menu.
If working in Code view, select the code for a component you want as the basis of your new 
custom component, right-click the selected code, and then select Create Local Component 
from the context menu.
The Save Component File dialog box appears.
3.
Name and save the component file.
4.
Insert your new component by selecting Insert > Local Component and selecting the 
component file.
Flex Builder will not replace the code you selected in Step 2. If you want, delete the code after 
inserting the new component.
5.
If the Flex server is running on a remote computer, copy the component file to the application 
folder on the server.
Make sure the application folder structure on the server matches the folder structure on your 
local computer, and that you copy the file to the same folder on the server. If you specified a 
remote folder when you defined your site in Flex Builder, you can use the Put command (Site 
> Put) to upload the file to the server. The Put command recreates the local folder structure on 
the server if it doesn’t exist.
If you move the component file to another folder on the server, such as the /WEB-INF/flex/
user_classes folder, then the namespace Flex Builder wrote in your MXML file might not be 
valid anymore. Modify the namespace as necessary by modifying the 
xmlns
 property of the 
component tag. For more information, see 
Including the component’s properties in code hints
Code hints in Flex Builder let you write MXML or ActionScript more rapidly. You can enhance 
this feature by including the properties of your custom components in the code hints.
For MXML component files, Flex Builder will include properties declared using MXML syntax. 
For ActionScript component files, Flex Builder will include only properties that are declared with 
an Inspectable statement. The Inspectable statement must immediately precede the property’s 
variable declaration. The syntax for the Inspectable statement is as follows:
[Inspectable(attribute=value[,attribute=value,...])]
property_declaration name:type;