EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 586

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
586 Creating Interaction with ActionScript
The first section of code defines the new class called DateFormat, which extends the
CustomFormatter class in the
mx.data.binding package. Remember that Flash compiles
the binding classes in the DataBindingClasses component file, so you cant view them
directly or find them within the Classes folder in the Flash install directory.
The only method you use is the
format() method, which converts the date instance into
a custom string format. The next step is to create an array of month names so that the end
result looks closer to
NOV 4, 2004 rather than the default date format. Remember that
arrays are zero-based in Flash, so if the value of
rawValue.getMonth() returns 1, it
represents February instead of January (because January is month
0). The remaining code
builds the custom formatted string by concatenating values and returning the
returnValue string.
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 isnt 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 Reported 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 “Using components, bindings, and custom
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 customFormatter object, which tells Flash that youre using the
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.

Table of Contents

Related product manuals