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

    creating shapes and adding them to canvas


      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

          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();


          • 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.drawCircle(30, 30, 30);
            var uic:UIComponent = new UIComponent();




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

            Greg Lafrance

            Flex Development and Support Services