Return to Snippet

Revision: 11850
at February 22, 2009 14:08 by chrisaiv


Initial Code
//A. Make sure the DataBinding Classes are in your library
//B. Import the EndPoint() object. Endpoints know about components, what is it, what property to look at, and what event triggers the data binding
import mx.data.binding.*;
import mx.controls.TextArea;

this.createClassObject( TextArea, "src_txt", this.getNextHighestDepth(), { wordWrap: true } );
src_txt.setSize( 200, 200 );
src_txt.move( 0, 0 );

this.createClassObject( TextArea, "dest_txt", this.getNextHighestDepth(), { wordWrap: true } );
dest_txt.setSize( 200, 200 );
dest_txt.move( 220, 0 );

//C. Create the source EndPoint()
var src = new EndPoint();
//D. First associate the src_txt component to the EndPoint
src.component = src_txt;
//E. Set which property we care about. If we wanted to find the value of a component, we might use "data"
src.property = "text";
//F. Set which event will trigger everything
src.event = "change";
//G. Create the destination EndPoint()
var dest = new EndPoint();
//H. Associated the component the the EndPoint()
dest.component = dest_txt;
//I. Make sure the right property is effected
dest.property = "text";
//J. Tell ActionScript which two components to Bind
new Binding(src, dest);

src_txt.text = "Change the text on the left side";

/*
//Anote Way to Do it with Less Code but not as "Proper"
var source = {component:src_txt, property:"text", event:["focusOut", "enter"]};
var dest = {component:myTextArea, property:"text"};
var newBind = new mx.data.binding.Binding(source, dest);
*/

Initial URL

                                

Initial Description
Create a new Flash AS2 file and paste this in the AS editor.

Initial Title
AS2: Simple Data Binding

Initial Tags

                                

Initial Language
ActionScript