Yeah, I agree, the "magic" in the scaleX/Y and width/height properties is
frustrating... it would be nice if someone (Adobe, hint, hint, nudge, nudge)
would provide a detailed explanation of what's happening under the hood and
what the expected functionality should be.

The only guaranteed thing I can find is that width/height are *always*
correct (in the parent's coordinate space) if I treat them as read-only and
using drawing to the sprite as a way to adjust its size. In other words, a
sprite doesn't appear to work as a general purpose container that I can size
to anything.

Personally, I think width and height should be like x and y, independent of
scale. My impression is that they wanted people to be able to load something
into a sprite and make it twice as big by saying mySprite.width *= 2. That
seems to conflict (or at least make non-trivial) the relationship between
scale and size, particularly in the edge case of an empty sprite (where size
is 0).

In the end, I think the API is *broken* design wise and is full of hacks to
make it work in the way people used it... but I may be wrong, hence my
desire for a definitive explanation from Adobe.

Troy.


On 6/1/07, esaltelli <[EMAIL PROTECTED]> wrote:

  Troy,

One thing to note in my trial and error, changing the height and width
then resetting the scales properly displays the content...until you
want to do a scaling operation. The very next scaling (i.e. via
scaleX = blah) operation uses the height and width computed from
'resetting' the scale. In my case all I wanted to do is perform
scaling operations. Attempting to restore the original image (via
scaleX = scaleY = 1.0 ) just didn't work after several scaling operations.

The only consistent mechanism I've discovered to date is to explicitly
create a new Matrix object and set it on the transform. Unfortunately
this seems to by-pass all of the properties; so you don't get an
updated height & width.

Ed

--- In [email protected] <flexcoders%40yahoogroups.com>, "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
> >
> >
> >
>

Reply via email to