2 Replies Latest reply on Dec 11, 2009 7:13 AM by Gregory Lafrance

    creating shapes and adding them to canvas

    flx23

      hi all

       

      How can we create shapes in flex..add them into a canvas i found code that used sprite but was unable to add .as it not being a uicomponent?

        • 1. Re: creating shapes and adding them to canvas
          Bogdan Manate Level 2

          This is because Canvas, or more specific, Container tries to cast our newly

          created Sprite to a UIComponent, which is an Object lower in the Flex

          inheritance chain and casting to a more specific type is not allowed. You could

          just add your Sprite to the rawChildren property of my container like this:

           

          var sprite:Sprite = new Sprite();

          canvas.rawChildren.addChild(sprite);

          • 2. Re: creating shapes and adding them to canvas
            Gregory Lafrance Level 6

            You need to wrap your sprite in a UIComponent. Accessing rawChildren can be dangerous.

             

            var mySprite:Sprite = new Sprite();
            mySprite.graphics.beginFill(0xFFCC00);
            mySprite.graphics.drawCircle(30, 30, 30);
            var uic:UIComponent = new UIComponent();

            uic.addChild(mySprite);

            this.addChild(uic);

             

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


            Greg Lafrance
            www.ChikaraDev.com

            Flex Development and Support Services