MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 583

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

4.
Select Control > Test Movie to test the document.
Flash changes the second value in the
. You successfully created a two-way connection.
out_ti
You can use the Binding classes with most user interface components of version 2 of the
Macromedia Component Architecture, not just the TextInput component. The following
example demonstrates how to use ActionScript to bind CheckBox instances and Label
components during runtime.
To use binding classes with the CheckBox component:
1.
Create a new Flash document.
2.
Select File > Save As and name the new file checkbox_as.fla.
3.
Select Window > Common Libraries > Classes.
4.
Drag a copy of the DataBindingClasses class into the document's library.
5.
Drag a copy of the CheckBox component onto the Stage and give it the instance
name my_ch.
6.
Drag a copy of the Label component onto the Stage and give it the instance name my_lbl.
7.
Create a new layer and name it actions.
8.
Add the following ActionScript to Frame 1 of the actions layer:
var srcEndPoint:Object = {component:my_ch, property:"selected",
event:"click"};
var destEndPoint:Object = {component:my_lbl, property:"text"};
new mx.data.binding.Binding(srcEndPoint, destEndPoint);
You use objects to define the endpoints instead of creating new instances of the EndPoint
class, as demonstrated in the previous exercises in this section. The code snippet in this
step creates two objects, which act as endpoints for the binding. You create the binding
when you call the constructor for the Binding class. To reduce the amount of code (and
readability) even more, define the objects inline as shown in the following snippet:
new mx.data.binding.Binding({component:my_ch, property:"selected",
event:"click"}, {component:my_lbl, property:"text"});
This ActionScript reduces the readability of your code, but it also reduces the amount of
typing you have to do. If you share your FLA (or ActionScript) files, you might want to
use the first snippet of ActionScript, because it is more reader friendly.
text input field and updates the value for
in_ti
Creating runtime data bindings using ActionScript
583

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

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?

This manual is also suitable for:

Flash 8

Table of Contents