22
Creating Advanced Components
You can also handle the
textChanged
event if you want to determine when the ModalText.text
property is modified, as the following example shows:
<mx:Script>
<![CDATA[
function handleText(event)
{
myText.text = "ModalText.text changed";
}
]]>
</mx:Script>
<mx:TextArea id="myText" />
<ModalText labelPlacement="left"
textChanged="handleText(event);"
/>
Note that to trigger the event, you have to modify the ModalText.text property directly; entering
text into the TextInput control does not trigger the event.
Troubleshooting
This section describes some common problems and their solutions when creating components for
Flex in Flash.
I get an error "don't know how to parse ..." when I try to use the component from MXML.
This means that the compiler could not find the SWC file, or the contents of the SWC file did
not list the component. Ensure that the SWC file is in a directory that Flex searches, and ensure
that your
xmlns
property is pointing to the right place. Try moving the SWC file to the same
directory as the MXML file and setting the namespace to "*" as the following example shows:
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
xmlns="*"
>
I get an error "xxx is not a valid attribute ..." when I try to use the component from MXML.
Ensure that the attribute is spelled correctly. Also be sure that it is not private.
I don't get any errors, but nothing shows up.
Verify that the component was instantiated. One way to do this is to put a Button control and a
TextArea control in the MXML application and set the
.text
property to the ID for the
component when the button is clicked. For example:
<!-- This verifies whether a component was instantiated. -->
<zz:mycomponent id="foo" />
<mx:TextArea id="output" />
<mx:Button label="Print Output" click="output.text = foo" />
I tried the verification test and I got nothing or "undefined" in the output.
This means that one of your dependent classes was either not loaded or was loaded too late. Print
various classes to the output to see whether they are being created. Any components created with
the
createClassObject()
method as subcomponents of your component must be placed in
your component symbol.
The component is instantiated properly but does not show up (#1)
.
In some cases, helper classes are not ready by the time your component requires them. Flex adds
classes to the application in the order that they need to be initialized (base classes, and then child
classes). However, if you have a static method that gets called as part of the initialization of a class,
and that static method has class dependencies, Flex does not know to place that dependent class
before the other class, because it does not know when that method is going to be called.
Содержание FLEX-CREATING ADVANCED COMPONENTS
Страница 1: ...Creating Advanced Components...
Страница 4: ...4 Contents...
Страница 24: ...24 Creating Advanced Components...