4 Replies Latest reply on Apr 23, 2010 8:43 AM by alice_data

    Multiple Instances Object Calling Getting #1009 Error

    alice_data Level 1

      Hi,

      I believe this has to be a logical explanation for this. I have the code here as follows:

       

      private function action():void{
           
          thematicMap.passBox(canvas,regions);
          thematicMap.drawthematicMap.passBox(canvas);  
             
          //Setting the Canvas
          thematicMap.setCanvas(0,0,30,50);     
          thematicMap.drawthematicMap.draw(regions);
          thematicMap.setCanvas(24,24,453,455);
          thematicMap.drawthematicMap.draw(regions);     
      }

      This does show two instances of the thematicMaps, which is what works in main.zip. However, what I really want to do is this:


      private function action():void{
           
          thematicMap.passBox(canvas,regions);
          thematicMap.drawthematicMap.passBox(canvas); 

                     a = new ThematicMap();
         b = new ThematicMap();  
          
          //Setting the Canvas
          a.setCanvas(0,0,30,50);
                      b.setCanvas(24,24,453,455);     

                     //Draw
                    a.drawthematicMap.draw(regions);
        b.drawthematicMap.draw(regions);     
      }

       

      The output of the application below is only a blank screen. I then investigated and added some try and catch clauses to see what errors there are,

       

      try {
               //Setting the Canvas
           a.setCanvas(0,0,30,50);     
           b.setCanvas(24,24,453,455); 
                   }
                    catch (errObject:Error) {Alert.show("An error occurred: " + errObject.message);}

       

      The results I got was Error #1009. How come that I have provided the parameters and the return is null object of reference?

      Thanks for your help.

       

      Alice

        • 1. Re: Multiple Instances Object Calling Getting #1009 Error
          David_F57 Level 5

          hi,

           

          the null object reference must being providing a lot more information, and the issue could be to what a & b relate to, is thematicmap a componet or a class that draws to the stage ?. More code is needed to see just what is what.

           

          David

          • 2. Re: Multiple Instances Object Calling Getting #1009 Error
            alice_data Level 1

            To answer your second point regarding if I had added a child to my  canvas to draw, here is the snippet:

             

            public function draw(arr:Array):void{
                       
                         regions = arr;    
                         component_width = [];
                         component_height= [];       
                        
                         for (var s:String in regions) {
                            trace("\n" + s);
                           
                            shape = new UIComponent();  
                            gr = shape.graphics;
                            gr.lineStyle(3);//Define line style  
                           
                            coords = regions[s];
                            gr.moveTo(coords[0],coords[1]);               
                         for (var i:int = 2; i < coords.length; i += 2) gr.lineTo(coords[i],coords[i + 1]);  
                             trace(coords);                
                             gr.lineTo(coords[0],coords[1]);    //return the code back to the beginning   
                             gr.endFill(); //Put this in if there is a color
                             canvas.addChild(shape);             
                       }              
                    }

             

            This is what is in my setCanvas function:

             

            public function setCanvas(x:Number,y:Number,width:Number,height:Number):void{       
                          
                        canvas.setActualSize(width,height);
                        canvas.x = x;
                        canvas.y = y;  
                        coordinate_conversion(regions);
                        new_coordinate_conversion(regions);
                    }

             

            What else could be wrong here?

             

            Thanks for your help.

             

            Alice

            • 3. Re: Multiple Instances Object Calling Getting #1009 Error
              David_F57 Level 5

              hi,

               

              So thematicmap is a component ?

               

              how is it declared ?

               

              when you use a = newthematicmap()

               

               

              have you declared var a:thematicmap,

               

              Does the null reference error tell you what line of code caused the null reference

               

              David.

              • 4. Re: Multiple Instances Object Calling Getting #1009 Error
                alice_data Level 1

                Hi,

                 

                  As I am writing this, I found out that I didn't reference any height or the information I would like to add. I have manipulated my code to:

                 

                public function action():void{  
                           
                     a = new ThematicMap2(canvas,regions);  

                          a.setCanvas(0,60,30,50);     
                          a.draw(regions);        


                     b = new ThematicMap2(canvas,regions);           
                           b.setCanvas(24,24,153,155);                         
                           b.draw(regions);   
                   }

                This is what I have in the ThematicMap2 class in the ThematicMap2 function:


                public function ThematicMap2(passedBox:Canvas,a:Array):void{
                              canvas = passedBox;
                              regions = a;            
                       }

                 

                Looks like everything is working now. Thanks.

                 

                Alice