6 Replies Latest reply on Jan 21, 2010 10:07 PM by harsh_hot

    Problem in drawing line

    harsh_hot

      Hi Friends,

       

      I am trying to draw a straight line on a panel but its not displaying the line. PFB my code,

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">

       

      <mx:Panel id="panel">    
              <mx:Script>
                  <![CDATA[


                      import mx.core.Container;
                      import mx.controls.Alert;          
                       import mx.utils.GraphicsUtil;
                     
                      private function init():void{

       

                var cont:Shape=new Shape();

       

                cont.graphics.lineStyle(3,0xFF0000,1);
                cont.graphics.moveTo(0,0);
                cont.graphics.lineTo(300,300);

       

                panel.addChild(cont);
      }
                     
                  ]]>
              </mx:Script>
             
      </mx:Panel> 

      </mx:Application>

       

      Where is the problem here? Also, please suggest how to debug flex applications.

        • 1. Re: Problem in drawing line
          RUSH-ME Level 3

          Hi

           

          It is better to use a canvas instead of panel. And add the shape to a uicomponent then add the uicomponent to the canvas.

           

          To debug a flex application you have to install flashplayer debug version.

           

          Hope this helps

          Rush-me

          1 person found this helpful
          • 2. Re: Problem in drawing line
            harsh_hot Level 1

            Thanks but it couldnt help me. I tried binding the shape to an hbox and then hbox to a canvas but no difference. I am still clueless.

            • 3. Re: Problem in drawing line
              iamfuric

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">

               

              <mx:Script>
                          <![CDATA[


                             
                              private function init():void{

               

                      

               

                        panel.graphics.lineStyle(3,0xFF0000,1);
                        panel.graphics.moveTo(0,0);
                        panel.graphics.lineTo(300,300);

               

                        }
                             
                          ]]>
                      </mx:Script>

               

              <mx:Panel id="panel" />    
                             

              </mx:Application>

              • 4. Re: Problem in drawing line
                Jason Szeto Level 3

                It all depends on where you are trying to draw the line. If you are trying to draw in the chrome (header, borders, etc), then I'd recommend creating your own skin that subclass PanelSkin. You can override drawBorder or drawBackground and add your drawing code there.

                 

                If you intent to draw a line across both the chrome and the content, then do something like this in the Panel's creationComplete event:

                 

                            protected function p_creationCompleteHandler(event:FlexEvent):void
                            {
                                var s:Sprite = new Sprite();
                               
                                s.graphics.lineStyle(3,0xFF0000,1);
                                s.graphics.moveTo(0,0);
                                s.graphics.lineTo(300,300);
                               
                                p.rawChildren.addChild(s);
                            }

                 

                Jason

                1 person found this helpful
                • 5. Re: Problem in drawing line
                  RUSH-ME Level 3

                  Hi

                   

                  First add the shape to UIComponent instead of hbox or vbox. Then add that UIComponent to the canvas. If this not solves your problem let me know.

                   

                  Hope this helps

                   

                  Rush-me

                  • 6. Re: Problem in drawing line
                    harsh_hot Level 1

                    Thanks everyone for the responses. It really worked!