The problem is that you are instantiating your SimpleExample object and
then trying to modify a component of the object before it is created.

You would need to move the instantiation of TextInput to the constructor
or instantiate it when you create the variable...

package
{
     import mx.containers.VBox;
     import mx.controls.TextInput;
     import mx.events.FlexEvent;

     public class SimpleExample extends VBox
     {
         private var child:TextInput = new TextInput();
         private var _text:String;

         public function SimpleExample()
         {
             super();
             addEventListener(FlexEvent.INITIALIZE, init)
         }

         private function init(event:FlexEvent):void
         {
             addChild(child);
         }

         public function get text():String {
             return _text;
         }

         public function set text(text:String):void {
             this.child.text = text;
         }
     }
}


--- In flexcoders@yahoogroups.com, Wesley Acheson <wesley.ache...@...>
wrote:
>
> Hi take for for example the following simple example. Its not a real
world
> example but it does show the problem that I wish to avoid.
>
> ---------------------------
> MXML (simpletest.mxml)
> ---------------------------
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute"
> xmlns:local="*">
>     <local:SimpleExample text="hello">
>
>     </local:SimpleExample>
> </mx:Application>
>
> ----------------------------------------------
> ActionScript SimpleExample.as
> ----------------------------------------------
> package
> {
>     import mx.containers.VBox;
>     import mx.controls.TextInput;
>     import mx.events.FlexEvent;
>
>     public class SimpleExample extends VBox
>     {
>
>         private var child:TextInput;
>
>         private var _text:String;
>
>         public function SimpleExample()
>         {
>             addEventListener(FlexEvent.INITIALIZE, init)
>         }
>
>         private function init(event:FlexEvent):void
>         {
>             child = new TextInput();
>             addChild(child);
>         }
>
>         public function get text():String {
>             return _text;
>         }
>
>         public function set text(text:String):void {
>             this.child.text = text;
>         }
>
>     }
> }
> --------------------------------
> If this is run I get a null error at set text.  How do I avoid this? 
Should
> I just just listen to the property change event on set text? Imagine
now
> that I had multiple different children.  Is there a method I can
override
> such as commitProperties so that all this will be done in the same
place.
>
> I'm sorry if this isn't too clear what I asking.
>
> Wesley Acheson.
>

Reply via email to