code_junkie

Flex 3 - Must I add components before setting their attributes when using AS3?

Nov 13th, 2011
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. var a:A = new A();
  2. a.b = "woopy"; //Sets the Label (declared in mxml) withn A to "woopy"
  3. this.addChild(a);
  4.  
  5. <customNamespace:A b="woopy"/>
  6.  
  7. var a:A = new A();
  8. this.addChild(a);
  9. a.b = "woopy"; //Sets the Label (declared in mxml) withn A to "woopy"
  10.  
  11. var a:A = new A();
  12. a.initialize();
  13. a.b = "woopy";
  14. this.addChild(a);
  15.  
  16. <?xml version="1.0" encoding="utf-8"?>
  17. <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
  18. <mx:Script>
  19. <![CDATA[
  20. [Bindable]
  21. public var labelText:String = "[Default]";
  22. ]]>
  23. </mx:Script>
  24. <mx:Label text="{labelText}"/>
  25. </mx:Canvas>
  26.  
  27. var a:A = new A();
  28. a.addEventListener(FlexEvent.INITIALIZE, a_initialize);
  29. addChild(a);
  30.  
  31. private function a_initialize(event:FlexEvent):void
  32. {
  33. a.b = "woopy";
  34. // ... and so on
  35. }
  36.  
  37. private var label:Label;
  38.  
  39. public function get b():String
  40. {
  41. return this.label.text;
  42. }
  43.  
  44. public function set b(value:String):void
  45. {
  46. this.label.text = value;
  47. }
  48.  
  49. private var label:Label;
  50.  
  51. private var _b:String;
  52.  
  53. public function get b():String
  54. {
  55. return this._b;
  56. }
  57.  
  58. public function set b(value:String):void
  59. {
  60. this._b = value;
  61. this.invalidateProperties();
  62. }
  63.  
  64. override protected function commitProperties():void
  65. {
  66. super.commitProperties();
  67. this.label.text = this._b;
  68. }
  69.  
  70. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
  71. <mx:Label text="{this.b}"/>
  72. <mx:Script><![CDATA[
  73.  
  74. private var _b:String;
  75.  
  76. [Bindable]
  77. public function get b():String
  78. {
  79. return this._b;
  80. }
  81.  
  82. public function set b(value:String):void
  83. {
  84. this._b = value;
  85. }
  86.  
  87. ]]></mx:Script>
  88. </mx:Application>
Add Comment
Please, Sign In to add comment