# How does flash store (represent) movieclips and sprites?

When we draw any object in flash and convert it into a movieclip or a sprite, how is it stored or represented in flash. I know in vector art it is stored or represented as line segments using formulae. Is there any way to get the vertices of the shape that was drawn?

For example, lets say a simple rectangle is drawn and is converted to a movieclip. Is there anyway to obtain the vertices and the line segments from the sprite? So that its shape is obtained. Enough information should be obtained so that the shape can be replicated. That's the key - replication.

In simple terms, where does flash store information about a shape that has been drawn so that we can obtain it and attempt to replicate the shape ourselves?

• What are you going to use this for? If we know what you are trying to achieve it will be easier to answer. Mar 18, 2011 at 19:53
• If you want to "replicate" exactly the same shape, why not simply clone it or create a new instance of it? Mar 18, 2011 at 20:36
• OK...here's what i'm trying to do...I'm using Box2D and I put sprites or movieclips as the Box2D object's 'skin'. Previously I created a combination of Box2D primitive shapes that resembled the sprite but it was never satisfactory as the sprite was not a regular shape...some bits were sicking out which were not over the underlying box2D shape. So I wanted a way to replicate the sprite's shape programmatically and create a Box2D shape that resembled the sprite's shape so that the collisions would look realistic there'll be no overlapping of sprites as in the previous case. Mar 19, 2011 at 7:11

If I interpreted your comment correctly, you want to: Have arbitrarily shaped sprites in Flash and automatically extract the shape of these sprites to use it as collision shapes in Box2d

Usually, collision shapes are much simpler shapes than the graphical asset they represent (performance). A highly detailed 3d Model can be represented just by a chamfered cylinder.

Some physic-bodies can be created automatically by algorithms, but it's also common practice to draw/model them manually. Unless you have a huge amount of different shaped sprites, it's most likely not worthwhile to implement an algorithm that extracts shapes for you.

If you have a look at the following image, you can see that a very complex shape can be represented by some circles and simple polygons (must be convex!). Drawing these shapes manually is (most likely) going to be superior to any algorithm you can come up with.

You could draw these shapes in a vector tool like Illustrator or Inkscape and export them to SVG, which can easily be parsed. Or use Flash and export the shapes as FXG, which is also a format that can easily be parsed.

If I haven't convinced you yet, and you really want to programmatically create the shapes from your sprites, here are two approaches that might work.

1. Render the sprite to a bitmap (using BitmapData.draw) and perform vectorization on the alpha-channel. If the resulting shape is concave, triangulate it.
2. Use the as3swf library to parse an existing SWF file in flash. You can extract shape-information from there. Your main problem here is going to be: Finding the shape(s) that form the outline of your object. Convert this shape into convex polygons.

"Flash" store all the information of the film or videogame into a own format. The data is stored in a vectorial format, this is a format that has a math definition. This is the main diference with bitmaps, because you can scale the image without data loss.

You can access to the .swf file, here is the specification (SWF and AMF Technology Center), and parse the movieclips, shapes, coordinates, etc. Because .swf format is very large you can use the code of SWFRIP project at http://sourceforge.net/projects/swfrip/ and see how you can parse a .swf file.

With a little patience you can obtain the data that you want.