3 Replies Latest reply on Jul 20, 2010 10:05 AM by Flex harUI

    Extending the Sprite class

    pbureau76

      Hello,

       

      I don't understand why the Sprite class cannot be extended and still directly displayed with addChild(). As is clearly exposed in the doc:

       

      http://livedocs.adobe.com/flex/3/langref/flash/display/Sprite.html

       

        public class SpriteExample extends Sprite {
              private var size:uint    = 100;
              private var bgColor:uint = 0xFFCC00;

              public function SpriteExample() {
                  var child:Sprite = new Sprite();
                  child.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
                  child.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
                  draw(child);
                  addChild(child);
              }

      [...]

       

      The SpriteExample class constructor will create a new Sprite, and this Sprite is the one added to the UI. I have tried to directly add the SpriteExample object to the UI but it will not display. Is there a reason for that or am I doing something wrong?

       

      Thank you in advance,

      Pierre