1 Reply Latest reply on Dec 10, 2010 11:18 AM by Flex harUI

    Adding an Image to a Sprite

    SiHoop Level 1

      I used the class below to draw a box into a Sprite by using graphics. Now I need to replace the simple box with a real graphic image. I thought I could simply add an Image to the Sprite, but this does not work. Why can't I add an Image to the Sprite and how should I fix it?

       

      Thank you.

       

      package {   
          import flash.display.Sprite;   
          import mx.controls.Image;   
          public class Marks extends Sprite{
              private var squareSize:Number=10;
              public function Marks(){
              }
              public function addMark(_x:Number, _y:Number):void{
                  var gradingImage:Sprite=new Sprite();
                  var image:Image=new Image();
                  image.source="images/image.jpg";
                  gradingImage.graphics.beginFill(0xeaea00);
                  gradingImage.graphics.drawRect(0,0,squareSize,squareSize);
                  gradingImage.x=_x
                  gradingImage.y=_y
                  gradingImage.addChild(image)
                  this.addChild(gradingImage)
              }           
              }
          }
      }