2 Replies Latest reply on Aug 26, 2009 5:29 AM by jake_flex

    Trying to understand ViewStack and child creation

    jake_flex Level 2

      I'm trying to work with the ViewStack, but keep on getting error 1009, which means that the object I'm trying to use is not created yet. I just dont understand why the object is not created and at which point will it get created.


      The attached code demonstrates my case. First time the combo box is changed, the error is reported and the value of t1.text is not changed. The second time the combo box is changed, the value changes, as it should.


      Now the question is, why is the object null on the first call? How to initialize the value and avoid this problem?




      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init(event)">
              import mx.collections.ArrayCollection;
              import mx.controls.Alert;
              private function init(event:Event) : void
                  var arr:Array = new Array();
                  arr.push("1", "2", "3");
                  combo.dataProvider = new ArrayCollection(arr);
                private function func(event:Event) : void
                       stack.selectedIndex = 1;
                       t1.text = "ok";
      <mx:ComboBox id="combo" change="func(event)" />
      <mx:ViewStack id="stack" x="29" y="108">
          <mx:Canvas id="zero" label="zz">
             <mx:TextArea id="t0" text="Zero"/>
           <mx:Canvas id="one" label="uno">
              <mx:TextArea id="t1" text="Numero uno"/>
           <mx:Canvas id="two" label="duo">
               <mx:TextArea id="t2" text="Number two"/>