EasyManua.ls Logo

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

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...
584 Creating Interaction with ActionScript
Using components, bindings, and custom formatters
Custom formatters help you format complex data in a specific way. You can also use custom
formatting to help display images, HTML formatted text, or other components within a
component such as the DataGrid. The following example illustrates how useful custom
formatters can be.
To use custom formatters in a document:
1. Create a new FLA file and add the DataBindingClasses class to the library (Window >
Common Libraries > Classes).
2. Drag a copy of the DateChooser component onto the Stage and give it the instance
name my_dc.
3. Drag a copy of the Label component onto the Stage and give it the instance name my_lbl.
4. Insert a new layer and name it actions.
5. Add the following ActionScript code to Frame 1 of the actions layer:
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);
This code creates a binding between the DateChooser's selectedDate property and the
text property of the Label component on the Stage. Each time you click a new date in the
calendar, the selected date appears in the Label component.
6. Save the Flash document as customformat.fla in a convenient location on your hard disk.
(You will recycle it in the next exercise.)
7. Select Control > Test Movie to test the document.
Try to change the dates in the Calendar component and you’ll see the currently selected
date appear in the Label component. The Label component isnt wide enough to display
the entire date, so Flash crops off the text.
8. Close the test SWF file and return to the authoring environment.
Either resize the Label component on the Stage or select the Label component and set the
autoSize property to left in the Parameters tab of the Property inspector.

Table of Contents

Related product manuals