Creating runtime data bindings using ActionScript
583
4.
Select Control > Test Movie to test the document.
Flash changes the second value in the
in_ti
text input field and updates the value for
out_ti
. You successfully created a two-way connection.
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.
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...