Guest User

Untitled

a guest
Aug 2nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Person.as:
  2. package
  3. {
  4.     [Bindable]
  5.     public class Person
  6.     {
  7.         public var name:String = "";
  8.         public var age:int = 0;
  9.  
  10.         public function Person(name:String="", age:int=0):void
  11.         {
  12.             this.name = name;
  13.             this.age = age;
  14.         }
  15.     }
  16. }
  17.  
  18. //Main.as:
  19. package
  20. {
  21.     import mx.binding.utils.BindingUtils;
  22.     import mx.binding.utils.ChangeWatcher;
  23.     import flash.display.*;
  24.     import flash.text.*;
  25.    
  26.     public class Main extends MovieClip
  27.     {
  28.         [Bindable]
  29.         public var person:Person;
  30.         public var name_tf:TextField;
  31.         public var age_tf:TextField;
  32.                
  33.         public var tf1:TextField;
  34.        
  35.         [Bindable]
  36.         [Bindable(event="change")]
  37.         public var tf2:TextField;      
  38.  
  39.         public function Main()
  40.         {
  41.             super();
  42.            
  43.             name_tf = new TextField();
  44.             age_tf = new TextField();
  45.             name_tf.border = age_tf.border = true;
  46.             age_tf.x = 100;
  47.             addChild(name_tf);
  48.             addChild(age_tf);
  49.            
  50.             ChangeWatcher.watch(this, "person", onPersonReferenceChange);
  51.             this.person = new Person();
  52.             this.person.name = "jan";
  53.             this.person.age = 21;
  54.            
  55.             ChangeWatcher.watch(this, "tf2", onTextFieldReferenceChange);
  56.             tf1 = new TextField();
  57.             tf2 = new TextField();
  58.             tf1.border = tf2.border = true;
  59.             tf1.type = TextFieldType.INPUT;
  60.             tf1.y = tf2.y = 100;
  61.             tf1.height = tf2.height = 24;
  62.             tf2.x = 100;
  63.             addChild(tf1);
  64.             addChild(tf2);
  65.         }
  66.         private function onTextFieldReferenceChange(event:Event):void
  67.         {
  68.             BindingUtils.bindProperty(tf2, "text", tf1, 'text');
  69.         }
  70.         private function onPersonReferenceChange(event:Event):void
  71.         {
  72.             BindingUtils.bindProperty(name_tf, 'text', person, 'name');
  73.             BindingUtils.bindProperty(age_tf, 'text', person, 'age');
  74.         }
  75.     }
  76. }
Add Comment
Please, Sign In to add comment