Thank a lot, Troy! (Your assumption is right, TCellView had to be CustomSprite.)
Due to your kind explanation, I got to know what is the problem. This explanation that the change of width/height causes the change of scale seems to make sense, obviously. It's really bad that there is no mention about this in Abobe's formal documentations. Thanks again. - Cho --- In [email protected], "Troy Gilbert" <[EMAIL PROTECTED]> wrote: > > Hi Cho, > > I assume in your example code below that TCellView was supposed to be > CustomSprite (i.e. the constructor). > > This was mentioned recently so you could probably find some details in the > archives, though I'm not sure what to suggest you search for, so I'll repeat > what I learned as best as possible: > > When you set the width and height of a sprite, Flash attempts to "scale" the > sprite to that width and height. So, it'll set the new width and height but > it will also adjust the scaleX and scaleY properties such that *if* your > sprite had content it would be scaled up to the new size (kinda what you > would expect if you resized a movie clip). > > Of course, the big problem is that the documentation for width/height (or > DisplayObject) makes absolutely no mention of this, and it appears that the > behavior has simply been deduced through trial and error (Gordon or other > Adobe folks, I'd love to see some official confirmation on what's happening > -- and an update to the LiveDocs!). > > What is happening in your case is the width and height of your new Sprite is > 0 because it doesn't contain any vector art, etc. So, you set the width and > height manually and the Sprite attempts to adjust scaleX and scaleY to > compensate. Since the width and height are at zero, the scales become NaN > (division by zero), and thus are set to zero. Now, future drawing/sizing > gets "squished" by the fact that scale is set to zero. > > To fix it, you can set your width and height *then* reset scaleX and scaleY > back to 1.0. That should do it. > > Adobe? Undocumented! > > Troy. > > > On 20 Mar 2007 05:43:55 -0700, celdi30 <[EMAIL PROTECTED]> wrote: > > > > > > 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 > > > > > > >

