Posted By

chrisaiv on 02/22/09


Tagged

as2 binding


Versions (?)

AS2: Simple Data Binding


 / Published in: ActionScript
 

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

  1. //A. Make sure the DataBinding Classes are in your library
  2. //B. Import the EndPoint() object. Endpoints know about components, what is it, what property to look at, and what event triggers the data binding
  3. import mx.data.binding.*;
  4. import mx.controls.TextArea;
  5.  
  6. this.createClassObject( TextArea, "src_txt", this.getNextHighestDepth(), { wordWrap: true } );
  7. src_txt.setSize( 200, 200 );
  8. src_txt.move( 0, 0 );
  9.  
  10. this.createClassObject( TextArea, "dest_txt", this.getNextHighestDepth(), { wordWrap: true } );
  11. dest_txt.setSize( 200, 200 );
  12. dest_txt.move( 220, 0 );
  13.  
  14. //C. Create the source EndPoint()
  15. var src = new EndPoint();
  16. //D. First associate the src_txt component to the EndPoint
  17. src.component = src_txt;
  18. //E. Set which property we care about. If we wanted to find the value of a component, we might use "data"
  19. src.property = "text";
  20. //F. Set which event will trigger everything
  21. src.event = "change";
  22. //G. Create the destination EndPoint()
  23. var dest = new EndPoint();
  24. //H. Associated the component the the EndPoint()
  25. dest.component = dest_txt;
  26. //I. Make sure the right property is effected
  27. dest.property = "text";
  28. //J. Tell ActionScript which two components to Bind
  29. new Binding(src, dest);
  30.  
  31. src_txt.text = "Change the text on the left side";
  32.  
  33. /*
  34. //Anote Way to Do it with Less Code but not as "Proper"
  35. var source = {component:src_txt, property:"text", event:["focusOut", "enter"]};
  36. var dest = {component:myTextArea, property:"text"};
  37. var newBind = new mx.data.binding.Binding(source, dest);
  38. */

Report this snippet  

You need to login to post a comment.