0 Replies Latest reply on Apr 8, 2010 1:01 PM by alice_data

    UI Component AddChild Not Showing Up?

    alice_data Level 1

      Hi,

       

        I have a code here where I read in the information from an XML file, and try to make shapes by plotting them to the screen. The problem is, it looks like it knows where each coordinate each shape goes, it is not showing up on the screen. What is even interesting is that it even knows that the shape and the canvas exists. Here is the output:

       

      There is shape
      Canvas Added
      region1 (10,10)
      region1 (20,10)
      region1 (20,5)
      region1 (10,5)
      region1 (10,10)

       

      Here is the code:

       

             public function draw():void{
                  
                 //set the starting point of the line
                   for (var s:String in regions) {
                                          
                   var shape:UIComponent = new UIComponent();
                   //define the line Style
                  shape.graphics.lineStyle(3,0x000000);
                 
                  //define the fill
                  //  shape.graphics.beginFill(0x666699);   
                   trace(s,regions[s][0]);
                    coordinates = regions[s][0].toString().split(",");
                    coordinate_conversion();
                    shape.graphics.moveTo(x,y);
                   
                   for(var i:int=1;i<regions[s].length;i++){
                             trace(s,regions[s][i]);
                            // move the line through a series of coordinates
                          coordinates = regions[s][i].toString().split(",");
                            coordinate_conversion();
                            shape.graphics.lineTo(x,y);
                    }                      
                        // move the line back to the beginning
                          coordinates = regions[s][0].toString().split(",");
                          trace(s,regions[s][0] + "\n");
                            coordinate_conversion();
                            shape.graphics.lineTo(x,y);
                            canvas.addChild(shape);
                            if(shape) trace("There is shape");
                           if(canvas.addChild(shape)) trace("Canvas Added");         
                    } //end for (var s:String in regions)                  
              }            
                   public function coordinate_conversion():void{                         
                    x = Number(coordinates[0]) * 10;
                    y = Number(coordinates[1]) * 10;
             }

       

      Could anyone please provide some insights on what error I have here? Why is it that my coordinates are printed out correctly, and yet my UI Component has never been added?

       

      Thanks for your help.

       

      Alice