580
Creating Interaction with ActionScript
You can use ActionScript instead of the Bindings tab to create bindings between components.
Adding code is often faster and more efficient than relying on the authoring environment.
Using ActionScript to create bindings is necessary when you use code to add components to
an application. You can choose to use the
createClassObject()
method to add components
onto the Stage dynamically; however, you couldn’t use the Bindings tab to create a binding
because the components don’t exist until runtime. Using ActionScript to add data binding is
often called
runtime data binding
.
For more information, see the following topics:
■
Creating bindings between UI components using ActionScript
■
“Using components, bindings, and custom formatters” on page 584
■
“Adding and binding components on the Stage” on page 587
Creating bindings between UI components using
ActionScript
It isn’t difficult to bind data between two components at runtime. You can do so in Flash
Basic 8 or Flash Professional 8. You must remember to include the DataBindingClasses
component in your document for it to work, because that component contains the classes that
you need to work with.
To create a binding between two TextInput components using ActionScript:
1.
Create a new Flash document called
panel_as.fla
.
2.
Drag two copies of the TextInput component onto the Stage.
3.
Give the components the following instance names:
in_ti
and
out_ti
.
4.
Select Window > Common Libraries > Classes and open the new common library called
Classes.fla.
5.
Drag a copy of the DataBindingClasses component into the Library panel, or drag the
component onto the Stage and then delete it.
You can close the common library after you finish. After you delete the
DataBindingClasses component from the Stage, Flash leaves a copy in the library.
TIP
If you forget to delete the DataBindingClasses component from the Stage, the
component’s icon is visible at runtime.
NO
TE
When you created a binding using the Component inspector in the previous
example, Flash added the DataBindingClasses component automatically to the FLA
file. When you use ActionScript to create data bindings, you must copy that class
into your library yourself, as shown in the following step.
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...