6.
Insert a new layer and name it actions.
7.
Add the following ActionScript to Frame 1 of the actions layer:
var src:mx.data.binding.EndPoint = new mx.data.binding.EndPoint();
src.component = in_ti;
src.property = "text";
src.event = "focusOut";
var dest:mx.data.binding.EndPoint = new mx.data.binding.EndPoint();
dest.component = out_ti;
dest.property = "text";
new mx.data.binding.Binding(src, dest);
If you prefer the somewhat shortened version, you could import the binding classes and
use the following code instead:
import mx.data.binding.*;
var src:EndPoint = new EndPoint();
src.component = in_ti;
src.property = "text";
src.event = "focusOut";
var dest:EndPoint = new EndPoint();
dest.component = out_ti;
dest.property = "text";
new Binding(src, dest);
This ActionScript creates two data binding end points, one for each component that
you're binding. The first endpoint you create defines which component it is binding from
(
), which property to watch for (
in_ti
(
). The second endpoint you create lists only the component and property
focusOut
(
and
out_ti
text
endpoints when you call the constructor for the Binding class (
).
dest)
You don't need to use fully qualified class names (such as
in your ActionScript, as you saw in the first code snippet. If you use the
at the beginning of your code, you can avoid using fully qualified names. When you
import all the classes in the
package includes both the EndPoint and Binding classes), you can shorten your code and
directly reference the EndPoint and Binding classes. For more information on import
statements, see the
8.
Select Control > Test Movie to test the code in the test environment. Enter some text into
the
text input field.
in_ti
After the
instance loses focus (click the Stage, press Tab, or click the second field),
in_ti
Flash copies any text that you input into
9.
Select File > Save to save your changes.
text
, respectively). Finally, you create the binding between the two
mx.data.binding
entry in the ActionScript 2.0 Language Reference.
import
), and which event will trigger the binding
mx.data.binding.EndPoint
package using the wildcard (
to the
in_ti
out_ti
Creating runtime data bindings using ActionScript
new Binding(src,
statement
import
(the
*)
text field.
)
581
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?