3 Replies Latest reply on May 28, 2010 3:24 AM by BhaskerChari

    Unable to draw lines

    TanweerHq Level 2

      Hi All,

      Currently I am developing a game. I need to draw some graphics on the stage.

       

      I created an as file to draw the line. The as fie is as follows

      **********************************

      package

       

       

       

       

       

      CustomPuzzle

      {

       

      import flash.display.Shape;

       

      import flash.display.Sprite;

       

       

      public class DrawPuzzle extends Sprite

      {

       

      public function DrawPuzzle()

      {

       

      var mySprite:Sprite = new Sprite();

      mySprite.graphics.beginFill(0xFFFFFF);

      mySprite.graphics.moveTo(100,100);

      mySprite.graphics.lineTo(200,200);

       

       

      }

      }

      }

      **********************

       

      In my parent file, I created the instance of the .as class as follows

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application

       

      creationComplete="CreateCompletePhase()" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#040404, #050303]">

       

       

      <mx:Script>

      <![CDATA[

       

      import CustomPuzzle.DrawPuzzle;

       

      private function CreateCompletePhase():void

      {

       

           var cust:DrawPuzzle = new DrawPuzzle();

       

       

      }

      ]]>

       

      </mx:Script>

      </mx:Application>

       

      But I am not able to draw the line..Please suggest me

        • 1. Re: Unable to draw lines
          BhaskerChari Level 4

          Hi,

           

          Try using the below code...

           

          package

           

           

           

           

           

          CustomPuzzle

          {

           

          import flash.display.CapsStyle;

           

          import flash.display.Sprite;

           

           

          import mx.graphics.Stroke;

           

          public class DrawPuzzle extends Sprite

          {

           

          public function DrawPuzzle()

          {

           

          var mySprite:Sprite = new Sprite();

           

          mySprite.graphics.beginFill(0xFFFFFF);

           

          mySprite.graphics.moveTo(100,100);

           

          mySprite.graphics.lineTo(200,200);

           

           

          var stroke:Stroke = new Stroke(0xFFFFFF,3,1,false,"normal",CapsStyle.NONE)

          stroke.apply(mySprite.graphics);

           

          mySprite.graphics.endFill();

           

          addChild(mySprite);

          }

          }

          }

           

           

           

          <?xml version="1.0" encoding="utf-8"?>

          <mx:Application

           

          xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="CreateCompletePhase();" layout="absolute" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#040404, #050303]">

           

          <mx:Script>

          <![CDATA[

           

          import mx.graphics.Stroke;

           

          import mx.core.UIComponent;

           

          import CustomPuzzle.DrawPuzzle;

           

           

          private function CreateCompletePhase():void

          {

           

          var cust:CustomPuzzle.DrawPuzzle = new CustomPuzzle.DrawPuzzle();

           

          var uiComp:UIComponent = new UIComponent();

          uiComp.addChild(cust);

          addChild(uiComp);

          }

           

          ]]>

           

          </mx:Script>

          </mx:Application>

           

           

          If this post answers your question or helps, please mark it as such.

           

           

          Thanks,

          Bhasker Chari

          • 2. Re: Unable to draw lines
            BhaskerChari Level 4

            You can also simply use this as file also....

             

            package

             

             

             

             

            CustomPuzzle

            {

             

            import flash.display.CapsStyle;

             

            import flash.display.Sprite;

             

             

            import mx.graphics.Stroke;

             

            public class DrawPuzzle extends Sprite

            {

             

            public function DrawPuzzle()

            {

            graphics.beginFill(0xFFFFFF);

             

            graphics.moveTo(100,100);

             

            graphics.lineTo(200,200);

             

             

            var stroke:Stroke = new Stroke(0xFFFFFF,3,1,false,"normal",CapsStyle.NONE)

            stroke.apply(graphics);

             

            graphics.endFill();

             

            }

            }

            }

             

             

            Always remember to call graphics.endFill() method when you use beginFill() method because after calling the endFill() method only the graphics is actually drawn or rendered.

             

            Thanks,

            Bhasker Chari

             

             

            • 3. Re: Unable to draw lines
              BhaskerChari Level 4

              ????