The first section of code defines the new class called DateFormat, which extends the
CustomFormatter class in the
the binding classes in the DataBindingClasses component file, so you can't view them
directly or find them within the Classes folder in the Flash install directory.
The only method you use is the
a custom string format. The next step is to create an array of month names so that the end
result looks closer to
arrays are zero-based in Flash, so if the value of
represents February instead of January (because January is month
builds the custom formatted string by concatenating values and returning the
string.
returnValue
A problem can arise when you work with classes within a compiled clip, which you can see
in the previous snippet. Because you extend a class that's located in the
DataBindingClasses class and it isn't readily available to Flash, you encounter the
following error when you check the syntax in the previous class:
**Error** <path to DateFormat class>\DateFormat.as: Line 1: The class
'mx.data.binding.CustomFormatter' could not be loaded.
class DateFormat extends mx.data.binding.CustomFormatter {
Total ActionScript Errors: 1
Your code is probably fine. This problem occurs when Flash cannot locate the class, and
because of this, syntax checking fails.
4.
Save the DateFormat.as file.
5.
Open customformat.fla from the exercise in
formatters". Make sure you save or copy DateFormat.as in the same directory as this file.
6.
In customformat.fla, modify the ActionScript code in Frame 1 of the actions layer to match
the following code:
import mx.data.binding.*;
var src:EndPoint = new EndPoint();
src.component = my_dc;
src.property = "selectedDate";
src.event = "change";
var dest:EndPoint = new EndPoint();
dest.component = my_lbl;
dest.property = "text";
new Binding(src, dest, {cls:mx.data.formatters.Custom,
settings:{classname:"DateFormat", classname_class:DateFormat}});
This time you define a
newly created DateFormat class to format the endpoint on the binding.
7.
Save the changes in your document and select Control > Test Movie to test your code.
586
Creating Interaction with ActionScript
mx.data.binding
format()
rather than the default date format. Remember that
NOV 4, 2004
Reported Errors: 1
customFormatter
package. Remember that Flash compiles
method, which converts the date instance into
rawValue.getMonth()
"Using components, bindings, and custom
object, which tells Flash that you're using the
returns
, it
1
). The remaining code
0
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?