Macromedia flex 2 Manuale
124
Creating Simple Visual Components in ActionScript
In this example, you first define the
MyComp
namespace to specify the location of your custom
component. You then reference the component as an MXML tag by using the namespace
prefix.
prefix.
You can specify any inherited properties of the superclass in MXML, as the following example
shows:
shows:
<?xml version="1.0"?>
<!-- as/MainDeleteTextAreaProps.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<MyComp:DeleteTextArea wordWrap="true" text="My Message"/>
</mx:Application>
<!-- as/MainDeleteTextAreaProps.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<MyComp:DeleteTextArea wordWrap="true" text="My Message"/>
</mx:Application>
You do not have to change the name of your custom component when you create a subclass of
a Flex class. In the previous example, you could have named your custom component
TextArea, and written it to the TextArea.as file in the myComponents directory, as the
following example shows:
a Flex class. In the previous example, you could have named your custom component
TextArea, and written it to the TextArea.as file in the myComponents directory, as the
following example shows:
package myComponents
{
{
import mx.controls.TextArea;
import flash.events.KeyboardEvent;
import flash.events.KeyboardEvent;
public class TextArea extends mx.controls.TextArea {
...
}
}
You can now use your custom TextArea control, and the standard TextArea control, in an
application. To differentiate between the two controls, you use the namespace prefix, as the
following example shows:
application. To differentiate between the two controls, you use the namespace prefix, as the
following example shows:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*" >
<MyComp:TextArea/>
<mx:TextArea/>
</mx:Application>
NOT
E
Your class must be specified as
public
for you to be able to access it by using an MXML
tag.