3 Replies Latest reply on Jan 15, 2011 9:50 AM by Gregory Lafrance

    problem with creatiocomplete event

    flx23 Level 1

      Hi All,

       

      i am calling the folliwing function on creationcomplete event of canvas which is the default component when add new mxml file to your project

       

      private function init():void

      {

       

                objIcity=new CityService();

                cityArray=objIcity.GetCity();

         

                  

                          dgCity.dataProvider=cityArray;

       

                          dgCity.visible=true;

                          lnkBCity.selectedIndex=1;

                   

       

      }

       

      the problem here is that it given error on bold line saying

       

      cannot access a property or method of a null object reference. as i hover dgcity which is advancedatagrid in my design code is displays it null..

      why is this happening as the control exists in the design..

       

      what i think this issue can be as on creationcomplete the controls are not created yet thats why its giving error..if this is the answer then where should i call this function to bind the advancedatagrid

       

       

      <mx:ViewStack id="vsCity" borderStyle="solid" width="100%" height="80%" color="0x323232">

       

                  <mx:VBox id="vbAddCity" label="Add City" backgroundColor="0xDCDCDC" width="100%" height="100%" fontWeight="bold" >

                     <mx:HBox>

                     <mx:Label id="lblCityName" text="City Name"/>

                     <mx:TextInput id="txtCityName" />

                     </mx:HBox>

                     <mx:HBox>

                     <mx:Button id="btnAdd" click="chkSelection()" label="Add City" />

                     <mx:Button id="btnCancel" click="txtCityName.text=''" label="Cancel" />

                     </mx:HBox>

                  </mx:VBox>

       

                  <mx:VBox id="vbViewCity" label="View City" backgroundColor="0xDCDCDC" width="100%" height="100%" fontWeight="bold" horizontalAlign="center" >

       

                      <mx:AdvancedDataGrid id="dgCity" visible="false" />

                  </mx:VBox>

       

       

       

       

              </mx:ViewStack></mx:VBox>

        • 1. Re: problem with creatiocomplete event
          jKnistrum

          Have you declared cityArray?

          • 2. Re: problem with creatiocomplete event
            flx23 Level 1

            yeah i have

             

            <mx:Canvas width="100%" xmlns:Controls="com.Controls.*" creationComplete="init()"  height="100%" xmlns:mx="http://www.adobe.com/2006/mxml" >

             

            <mx:Script>

            <![CDATA[

            private var objIcity:ICity;

            private var cityCount:int;

            private var cityArray:Array;

            private var lblMsg:Label;

            private var cityParam:City;

             

            private function init():void

            {

             

            objIcity=new CityService();

            cityArray=objIcity.GetCity();

              

                if(cityArray!=null)

            {

            dgCity.dataProvider=cityArray;

             

            dgCity.visible=true;

            lnkBCity.selectedIndex=1;

            }

            else

            {

            lnkBCity.selectedIndex=0;

            lblMsg=new Label();

            lblMsg.text="Please add a city";

            vbViewCity.addChild(lblMsg);

             

             

            }

             

            }

            ]]>

            </mx:Script>

            • 3. Re: problem with creatiocomplete event
              Gregory Lafrance Level 6

              By default the ViewStack only creates the first "view" and its children. Set creationPolicy="all" and you should have no error.

               

              Setting creationPolicy="all" can be a performance hit if there are many views with lots of UI. In that case you may need to find another way to ensure anything that must exist at creationComplete has been initialized.

               

              If this post answers your question or helps, please mark it as such. Thanks!

              http://www.stardustsystems.com
              Adobe Flex Development and Support Services