How to extract the shape of MovieClip? - actionscript-3

We have a flash application that we are planning on converting to javascript. It's a pretty simple map application with an image as the background and a bunch of simple polygon movie clips that represent destinations on the map.
I would like to iterate through each movie clip and extract the shape into an array of x,y points to redraw the polygon using an external javascript function.
Is this possible with actionscript?

If you want to export the shape coordinates at author time, you can do try the JSFL script recommented by #strille or this one or export transparent images (if that's not too limiting for your application).
If you need to export the shapes at runtime, you can use the awesome as3swf library to decompile the swf and export the shapes. Have a look at the ShapeExport wiki as there are couple of handy exporters for js like JSCanvasShapeExporter and the more generic JSONShapeExporter

There are ways you can read the coordinates from an SWF. For instance, I've written a parser in PHP (link). Getting the data doesn't help though, as it turns out. The Flash painting model is different enough from the HTML5 one enough to make transfer exceeding difficult. The main obstacle I discovered is that in Flash, a path can be filled with two fill styles: one for area enclosed by the path, the other for enclosed area considered to be "outside" by the even-odd rule (e.g. the pentagon in the middle of a star). Since the HTML5 canvas let you specify only one fill style, you can't redraw shapes from Flash accurately. I was trying to create a tool that extract shapes as SVG and was getting a lot of gap and holes in the result.

Flash Player 11.6 introduced readGraphicsData() which does exactly what you ask for.
If you need to target an earlier version, then there's no simple way to read shape coordinates from a display object with ActionScript at runtime unfortunately.
If you just want to extract the shape coordinates once someone has written a jsfl script for Flash CS3 which looks like it might be able to help you out.

Related

Move SWF shape points with as3 code

I have SWF vector shape, how to get access to control points of this shape? I want to move some points of this shape with as3 code. SWF created with flash professional CS5, code in flash develop.
Other way to create some Sprites in CS5, and move them with as3, but how to tie them with shape control points?
Employ readGraphicsdata() to read the GraphicsPath of your shape, it contains commands and control/anchor points. You can then parse that vector to find out the point you want to alter, then you change it, then you feed the path back into your shape via graphics.clear(); graphics.drawPath(path);, or use drawGraphicsData() instead to draw the complete set of graphics shape.
The manual on readGraphicsData()
The manual on GraphicsPath class format

Anyone know a list of flash.includes? (as3)

I'm looking for a list of flash.include.whatever.whatever for as3.
If no one knows a list then can someone tell me the flash.include to use for drawing rectangle with the startFill and endFill things? Thanks for any help.
I didn't find anything on either of these googling, and the place I got the code for drawing a rectangle of course didn't have the flash.includes included in the example code... is their a reason so many people do that? Any way I can get around it?
Do you mean you want a list of the packages and classes that come with AS3? That is typically called the documentation and can be found here:
Adobe ActionScript® 3 API Reference
For drawing a Rectangle, you can start at flash.display.Shape. It has a graphics object with the methods .beginFill() and .endFill().
you can using a Graphics.
The Graphics class contains a set of methods that you can use to
create a vector shape. Display objects that support drawing include
Sprite and Shape objects. Each of these classes includes a graphics
property that is a Graphics object. The following are among those
helper functions provided for ease of use: drawRect(),
drawRoundRect(), drawCircle(), and drawEllipse(). You cannot create a
Graphics object directly from ActionScript code. If you call new
Graphics(), an exception is thrown.
The Graphics class is final; it cannot be subclassed.
here is a sample
import flash.display.*;
this.graphics.beginFill(0xff0000);
this.graphics.drawRect(0,0,100,100);
here is a Adobe Tutorial
AS3 all display class list here
You do not necessarily need to default AS3 include. fine compile. But include only the code you can see the hint. perhaps, CS4 after that if you use a specific class will automatically include. or ctrl+space is autocompletion.
As follows by default when you install the flash is because of the SWC path.
As per I know, there is not such a thing like Flash.include. May be you're trying to ask something else or may be i am still unknown about this feature.
If you found any positive thing about this, please let me know, i want to know that new thing.

AS3 Defining coords for a screenshot?

I've built a photo booth app for an installation and I need to take a screen shot of the bitmap data with it's frame... I foolishly nested my objects all wrong way too early in the game so taking a picture of just the display object is moot at this juncture, and I dont have time to re-organize everything.
I know the encoder can output stills of the stage, but can that be a defined set of coords? I have an 800x600 region that needs to output, ignoring the rest of the stage.
I am playing with other options as well, but if there is anything that seems obvious, i would greatly appreaciate it!
You can get the whole stage as a bitmap data and then use the copypixels method to copy the region you need.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#copyPixels%28%29
Or you can use the draw method of BitmapData class to draw a display object into that bitmap data.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#draw%28%29

actionscript library for interactive path drawing (or any other library for the equations

I am making a flash app where I want to have a user defined viewport like the stage in the flash IDE which the user can use to define objects that have a starting postition somerwhere off or on the stage and an ending position either or on or off the stage with the object then tweening between the two points.
My question is this: I want the user to be able to define a curved path for the object to tween along. Is there a library of code that I can use to define curved paths for the app?
Ideally I would like something similar to the functionality available in Flash, so a bezier curve sort of path that is subdivided into handles that can be dragged to define the path of the tween.
If there isn't an existing library, then do you know of the functions that I would need to define (mathematical equations related to drawing curves etc)?
Many thanks
You could use TweenMax with the BezierPlugin
Or define the path elsewhere and use LinePath2D

ActionScript / Flash - Programatically Bitmap-Fill IDE Drawn Vectors?

my current situation maybe akin to me painting myself into a corner.
i have many vector shapes drawn with the Flash Professional CS5 IDE, which have been converted into sprite objects and exported to actionscript. for example, here are 3 shapes:
i want to programatically fill each shape with a bitmap from my library. i realize i can fill these shapes with library bitmaps in the IDE, but i need to scale the bitmaps at runtime as well as swap them out for others.
how is it possible to programatically bitmap-fill shapes drawn within the IDE at runtime without having to also programatically redraw them?
what about using your shapes as masks rather than going through a painful on the fly drawing process ?
it would go like :
bitmap.mask = shape;
as long as shape is a DisplayObject, it should work.
otherwise you can still use a JSFL to export your shapes, store them as arrays of points and draw them at runtime.
here's a basic JSFL export tool
http://ericlin2.tripod.com/bugwire/bugwiret.html
here's an advanced JSFL tool:
http://www.lidev.com.ar/?p=192
here's a ( shamelessly self-promoting :) ) example of an application:
http://en.nicoptere.net/?p=1331
[EDIT]
NB when compiled, your vector shapes are turned into opcode, a set of instructions that you can't read easily.
it remains possible though: http://wahlers.com.br/claus/blog/hacking-swf-1-shapes-in-flash/ but still it's a bit complex if the same result can be achieived with masks :)