views:

529

answers:

4

I have problem when dealing with transform in Flash cs4 ....

When I rotate my movieclip and trace the output, my movieclip's width also changed....

A: 

I'm not sure why this is a problem - it's expected behavior. The width of a clip is the actual number of pixels from the left most edge to the right most edge - which will change if a clip is rotated. If your clip has a sub-clip within it, that clip's width will not change, since presumably it's rotation isn't changing.

Branden Hall
This is a bug in Flash. While the BoundingBox (which you describe) should change, the width should return the actual width of the content, not scaled and not resized.
Virusescu
A bug would imply that this behavior is errouneous in some way - it is not. The meaning of width and height in Flash has always meant at the point of actual display, not prior to scaling, rotation, etc. If you want to ignore that information then you need to stack content inside and measure the internal clips.
Branden Hall
Please view my response for an example of why I think this behavior is erroneous. From what you say, retrieving a Sprite's original size would be quite a task.
Virusescu
Just because something doesn't work the way you want it to does not make it erroneous or a bug.
Branden Hall
Please check PiPeep's link posted in his comment from Grant Skinner. I've deviated based on lack of example. You are right on that width vs boundingbox widht stuff, but check to see the weird problem described. That scenario is happening in Flash CS3 with AS 3. My guess is that it was an actionscript problem and maybe fixed in CS4 (but I don't have CS4 to test now).
Virusescu
+1  A: 

This is a bug in flash player. There are a few things you can do:


Option 1 (probably the best way):

Create a subclass of MovieClip and override the get and set methods for width and height. Have the setters call super, and store the values as private variables (eg _width/_height) When get is called, return your private variables. Since you are using a matrix, override the get and set matrix functions, set the scaling factors with your new functions, and set them to not scale before calling super. Why this works: The setters are not affected by this bug.


Option 2:

Use scaleX/scaleY instead for getting the width/height, and multiply by the width and height values for 0 rotation, 1.0 scale. Why this works: The scaleX/scaleY are not affected by this bug.


Happy Coding!

PiPeep
this is not a bug. the flash player has always worked this way.
grapefrukt
http://www.gskinner.com/blog/archives/2007/08/annoying_as3_bu.html
PiPeep
This IS a bug in Flash. The Flash Player behaves like this from FP8 if I recall correctly. Or, ok if you don't want to name it a bug, then it's a major confusing change nonetheless.
Virusescu
A: 

width/height will change as you rotate the clip. if you don't want this behaviour, use the scaleX/scaleY properties instead.

grapefrukt
+1  A: 

OK .. MY BAD.. I've seen my error eventually :). I was convinced this was a bug before. Though Branden was right, I still find it pretty confusing. This is eventually an example to show that Branden was right and there is no discrepancy between the last 2 values.

var box = new Sprite();
box.graphics.beginFill(0xFF0000);
box.graphics.drawRect(0, 0, 100, 100);
this.addChild(box);

trace(box.width);
box.rotation = 45;
trace(box.width);
box.width = 141.4;
trace(box.width);

Edit: You'd still might want to check PiPeep's link form grantskinner describing something like I wanted to prove above, but successuly (in Flash CS3 - AS3) - http://www.gskinner.com/blog/archives/2007/08/annoying%5Fas3%5Fbu.html

Virusescu