6 Replies Latest reply on Feb 5, 2010 6:01 AM by NonTakenUserName

    Error 1009 : Strange




      I'm new to Flex development, and I'm trying to build an application that load content of an image and display it on screen, and then resize, move, rotate it.


      The problem is that i'm able to load my image, but, sometimes, it display the following message : TypeError: Error #1009: Cannot access a property or method of a null object reference. (Not all the times, but almost)


      In the code,

      there is a line that look like this :

      <nomadlogic:ImageFlexShape id="flexShape1" imageLocation="{pictureSource}"  imageLoaded="imageLoaded();"/>


      if I  replace the {pictureSource} by the real source (ex : htttp://www.domains.com/image) it's work fine.

      The pictureSource var is well initialized(voir mx:Application :  preinitialize="initializeParams()") t the initializeParams method (Alert.show()).

      pictureSourceis taken from application parameters  (mx.Application.application.parameters.picture = http://www.domain.com/image)


      What should I do to correct this error??

      I've never see where, in the code, this error happen.


      Here's my main app code (I'Ve removed imports to reduce scrolling, but the code compile well) :


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
           backgroundGradientAlphas="[1.0, 1.0]"
           width="100%" height="100%"
           click="backgroundClick(event);" >




                  protected var parametersHandler:ParametersHandler;

                  [Bindable]protected var resizedBackgroundWidth:Number = 0;

                  [Bindable]protected var resizedBackgroundHeight:Number = 0;

                  [Bindable]protected var pictureSource:String;


                  protected function initializeParams() : void



                      try {

                          parametersHandler = new ParametersHandler(mx.core.Application.application.parameters);

                          resizedBackgroundWidth = parametersHandler._resizedBackgroundWidth;

                          resizedBackgroundHeight = parametersHandler._resizedBackgroundHeight;

                          pictureSource = parametersHandler._pictureSource;

                      } catch (error:Error)


                          Alert.show("ERROR while loading parameters");




                  protected function imageLoaded(): void {




                  protected function backgroundClick(event:MouseEvent) : void





                  protected function onSaveBtnClicked():void {

                      Alert.show("Save btn Clicked!");



                  protected function onCancelBtnClicked():void {

                      var urlString:String = "javascript:window.opener = self; self.close();";

                      var request:URLRequest = new URLRequest(urlString);

                      navigateToURL(request, "_self");



                  protected function onResetBtnClicked():void {






          <mx:Image id="background" source="c:/test2.jpg" height="{resizedBackgroundHeight}"

              width="{resizedBackgroundWidth}" />

          <nomadlogic:ImageFlexShape id="flexShape1" imageLocation="{pictureSource}"


          <mx:Button id="saveBtn" click="onSaveBtnClicked()" label="Save"  x="850" y="300" width="100" />

          <mx:Button id="cancelBtn" click="onCancelBtnClicked()" label="Cancel" x="850" y="330" width="100" />

          <mx:Button id="resetBtn" click="onResetBtnClicked()" label="Reset" x="850" y="360" width="100" />





      ImageFlexShape is a as file, extends UIComponent. It draw image using the paint() method.


      here is the code to load the image :

      var request:URLRequest = new URLRequest(url);            
      var imageLoader:Loader = new Loader();
      imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, image_completeHandler);


      Thanks for your help!!!


        • 1. Re: Error 1009 : Strange
          NonTakenUserName Level 1

          Can you provide more code? It will be harder to come to a definitive answer from just reading the code and it won't compile as it is (since the nomadlogic:ImageFlexShape and ParametersHandler classes are missing)


          Which line in the code is causing the error?

          • 2. Re: Error 1009 : Strange
            alekss_d Level 1



            There is no line number given by this error message, no line number in debug mode too.



            I just don't understand why when I take the picture source from the parameters it's not working, but when I hard code the source (same source that the one in parameter) it's working perfectly.


            I've attached my code files. (zip)



            • 3. Re: Error 1009 : Strange
              NonTakenUserName Level 1

              Ok, here's what's happening in my local copy:


              ImageFlexShape.as, line 91:


              matrix.scale(this._model.width / _imageBitmap.width, this._model.height/ _imageBitmap.height);


              _imageBitmap is null


              As to why it's null:


              image_completeHandler is never called, which means imageLoader never fires Event.COMPLETE, but updateDisplayList is still called, which causes redraw to be called, which gets to line 91


              In ParametersHandler.as, _pictureSource is coming from In my copy I obviously get no response from that address, since I have no access to it. Are you getting a response back from this address?


              If I change the value of _pictureSource in the ParametersHandler for a direct URL to an image, the whole thing loads fine (I tested it with http://www.google.com/images/nav_logo7.png)

              1 person found this helpful
              • 4. Re: Error 1009 : Strange
                alekss_d Level 1



                This address is a local server. It will not be accessible over the internet.


                Now, In the html-template/index.template.html file, there is the parameters, next the testFlex.swf?. Add a parameter named &pictureSrc=





                Try read it from parameterHandler and set _pictureSource to it

                _pictureSource = params.pictureSrc;



                "respondent_id=" + this._repondantId +

                "&synchro_no=" + this._synchroNo +

                "&project_no=" + this._projectId +

                "&lg=" + this._language;*/


                Now, try running the application. You will have the same error message as me. I don't understand why I get an error message when taking the image source from parameters.


                If I try with the google image that you have used, the error messge never appear. But wih this picture, it appear all the times.

                Maybe it's too long to load and I try to access the properties before it's loaded.



                • 5. Re: Error 1009 : Strange
                  alekss_d Level 1

                  You were right, line 91 cause this problem. Sometimes, it try to draw before image was loaded.

                  I just add this line in the draw method :



                  (!_model || _imageBitmap == null){return;}



                  When I was loading small image, the message never appear because Flex have loaded the picture before draw was called.

                  When loading large pictures, the draw method was called before the picture was loaded corectly.





                  • 6. Re: Error 1009 : Strange
                    NonTakenUserName Level 1

                    Ah, yes. The image size delaying the load completion makes sense. Glad I was able to help.