|
-
Height / width of bounding box of visible area
I have imported a bunch (actually, over 1000!) jigsaw puzzle pieces into FLA files from Illustrator CS3.
In many cases the pieces have artifacts outside of their visible area. For example, a piece can have a picture of a dog's face, but one of the long ears is off to the side, outside the visible region of the piece. The path data is extremely detailed, so our designers didn't crop it off. They used a mask (at least I think it's a mask, I'm not a graphics guy and know little about that stuff) and this makes it invisible in Flash, when we turn them into movie clips. Also, in Flash when I look at the width and height of the piece, it does reflect only the visible area.
However, in ActionScript when I try to get the width and height using, for example I get the width of the piece including the part that is hidden, i.e. a larger width than the visible area.
Is there a way in AS 3.0 to get the height / width of the bounding box of visible area only?
Thanks.
Last edited by anroy; 06-23-2008 at 12:21 PM.
-
A picture is worth a thousand words. Here is the puzzle piece, showing the visible and invisible areas.
I brought out the invisible areas by pressing Command-B (break apart). I'm not too sure of what the invisible area really is, data-wise.
All I want is the be able to get the height and width of the visible area (the red part in the second picture) from within ActionScript.
-
Your image isnt coming through due to some security on the server...
For bounding issues with transparent members, the only way I know to go about fixing that is to draw the whole thing into a bitmap and then use the getColorBoundsRect method to crop down anything on the margins...it's pretty processor intensive so I dont know if it would work with 1000+ pieces without a significant slowdown.
Do you absolutely need the width? Is there some other way you could achieve the same effect without relying on that piece of info?
-
 Originally Posted by neznein9
Your image isnt coming through due to some security on the server...
Darn, my bad, I put them in a protected folder.
Here they are again.
Visible area

Entire piece

 Originally Posted by neznein9
For bounding issues with transparent members, the only way I know to go about fixing that is to draw the whole thing into a bitmap and then use the getColorBoundsRect method to crop down anything on the margins...it's pretty processor intensive so I dont know if it would work with 1000+ pieces without a significant slowdown.
You'd think there'd be a vector data way to do this. After all, in the Flash IDE when I select the movie clip the width and height properties are those of the visible area. So the information is in there somewhere.
I wonder why the difference between values in the IDE and those returned in ActionScript from the width and height properties of the DisplayObject.... that's one part of this that really gets me.
 Originally Posted by neznein9
Do you absolutely need the width? Is there some other way you could achieve the same effect without relying on that piece of info?
I did find a workaround. I posted this after the fact because I still want to get to the bottom of it.
Here's my workaround anyway, in the off-chance it helps anyone:
When the piece is placed by the user I was using hitTestObject to determine if it made contact with the target area (which was another movie clip). Well, I suspect that hitTestObject uses the width and height information because that would be consistent with the results I was getting (and it makes sense when you consider what it does).
So I stopped using hitTestObject and instead am measuring the distance between the center point (the registration point) of the piece and the target area object, and if they are within a certain number of pixels from each other I treat it as a "hit".
-
In regards to the IDE vs. runtime, remember that masking is only evaluated in the player - and objects with zero-alpha will still take up space...
For your hittest problem, look at the index in the livedocs - there are a few different hit tests that will give you either bounding-box collision or per-pixel detection.
-
 Originally Posted by neznein9
In regards to the IDE vs. runtime, remember that masking is only evaluated in the player - and objects with zero-alpha will still take up space...
The fact that the player is "aware" of the masking indicates that there has to be a way to get the bounds of the visible area.
I'll try to read everything I can get my hands on regarding dealing with masks from an ActionScript perspective and report back here. It's bugging the heck out of me.
 Originally Posted by neznein9
For your hittest problem, look at the index in the livedocs - there are a few different hit tests that will give you either bounding-box collision or per-pixel detection.
There are three, none of them suited my purposes.
- hitTest is for bitmaps.
- hitTestObject is what I used and was the reason I started this thread. It works with bounding boxes but seems to use the entire object, not just the masked visible area.
- hitTestPoint determines if a point overlaps the object or not, and it does have a flag parameter to indicate if you want to use the bounding box or per-pixel.
The workaround I described in my previous post works fine. I'm just pursuing this topic so that I (and hopefully anyone else) can get an understanding of the issues when you import data from Illustrator with masks. It's been a veritable nightmare.
-
For code to determine the visible dimensions of a display object, see:
http://www.moock.org/blog/archives/000292.html
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|