3 Replies Latest reply on Nov 19, 2011 1:28 PM by Alan321977

    Error loading data from an XML file using HTTPService


      Hello All,


      I have a runtime error that has got me beat at the moment   I am building an App in Flash Builder 4 to run on AIR.

      The error is as follows: TypeError: Error #1009: Cannot access a property or method of a null object reference.


      What i'm Trying to Do:

      I have 2 DropDownList controls, the first is populated with country names and the other with language options.  All the 1st DropDownList control does

      is set an image control to display the country flag and enable the 2nd DropDownList.


      The 2nd DropDownList sets the langCode variable equal to the chosen language code.  I then call the language function and pass it langCode.  Using this variable, I build up the string

      so that langFilePath will be equal to the XML file (which is "Lang_GBR.xml") location on my desktop and then call the HTTPService.


      As soon as the language function is called, the runtime error occurs and highlights the line with btn_LS_mainMenu.label = loadLangService.lastResult.Lang.GlobalTags.btnMenu;

      where I try to assign the button label with a new value from the XML file.


      I suspect this may be a trivial error but I just can't see it at the moment. 


      Any help or guidance would be appreciated.  Thanks




                     public var langFilePath:String;
                     public var langDir:File = File.desktopDirectory;
                     public var langCode:String;
                     public function countrySelect_changeHandler(event:IndexChangeEvent):void
                          switch (countrySelect.selectedItem)
                               case ('United Kingdom'):  
                                    trace("Item Selected was: "+ countrySelect.selectedItem);
                                    img_countryFlag.source = AngolaFlag;
                               case ('France'):  
                                     trace("Item Selected was: "+ countrySelect.selectedItem);
                                     img_countryFlag.source = AustraliaFlag;
                          langSelect.enabled = true;
                          trace("1st dropdownbox");
                     public function langSelect_changeHandler(event:IndexChangeEvent):void
                          switch (langSelect.selectedItem)
                               case ('English'):  
                                   trace("Language Selected was: "+ langSelect.selectedItem);
                                   langCode = "Lang_GBR";  
                               case ('French'):  
                                   trace("Language Selected was: "+ langSelect.selectedItem);
                                   langCode = "Lang_FRA";  
                     public function language(aParam:String):void
                          trace("Code Was: " + aParam);
                          trace("Lang dir: " + langDir.nativePath);
                          langFilePath = langDir.nativePath + "/" + aParam + ".xml";
                          trace("File to load: " + langFilePath);
                          trace("loadLangFile.url: " + loadLangService.url);
                          btn_LS_mainMenu.label = loadLangService.lastResult.Lang.GlobalTags.btnMenu;
           <s:HTTPService id="loadLangService" url="{langFilePath}"/>
      <s:DropDownList x="10" y="201" id="countrySelect" prompt="Please Select Your Country" width="274" enabled="true" change="countrySelect_changeHandler(event)">
      <s:DropDownList x="10" y="348" id="langSelect" prompt="Please Select Your Language" width="274" enabled="false" change="langSelect_changeHandler(event)">