Hi all. (This is my first post in this group, so I'd like to give all of
you a greeting .)

As the title, I've met an odd problem with using Sprite class.
Because I'm a novice of Flex, my problem may be so trivial.
But Your helps would make me happy.

The simple version of my code is below.

public class CustomSprite extends Sprite
{
     public function TCellView(w:Number, h:Number) {
         this.width = w;
         this.height = h;

         draw();
   }

    private function draw():void {
         this.graphics.clear();

         this.graphics.lineStyle(2, 0x000000, 0.7);
         this.graphics.drawRect(0, 0, this.width, this.height);
   }
  }

The problem is that the assignments to width and height in the
constructor of mine have no effect.
So in draw(), the  rectangle to be drawn has size of zero. The width and
height are public properties of Sprite and are not read-only.
Then why does the code like 'this.width = w' have no effect? (In debug
mode of Flex Builder, the Variables view told me the values of
width/height of the Sprite object have not changed by the codes.)

After some investigation, I knew that the drawing on the graphics of
Sprite causes update of width/height.
That behavior is reasonable, I think. However, I wonder why a
direct-assignment to width or height is banned, and how.

Is there any mistake in my code? Or Do I misunderstand something?
Please, tell me what's going on behind the scene about Sprite.
Any replies of you would be grateful.

Thank you.
- Cho


Reply via email to