开发者

Flash / AS3 - How do you get the points of a path drawn in Flash

Is it possible to draw a path in flash, and access the points from AS?

For example if I have a map and I add hidden paths along various roads, I then later want to animate traffic or growing lines along these predefined paths 开发者_运维技巧from code.


I have never tried it, but technically it should be possible using a library like as3swf, which is a SWF parser written in actionscript.

You would have to parse the SWF containing the path using the parser library and then extract the needed coordinates from the output.

That procedure seems horribly backwards to me though. A simpler, more feasible approach would be to draw your paths in Flash, select them and export them using: File > Export > Export Selection..., then export as Adobe FXG. This will export your Paths as FXG XML file.

You can then parse the FXG file in flash and extract the path coordinates that are interesting for you. Shouldn't be that hard to implement. Also have a look at the Path class docs, as it contains some information about how coordinates are stored and should be interpreted.


You might think it reasonable to expect this in the worlds leading 18 year old, scriptable-vector-drawing app, but you would be wrong.

You might be able to get the effect you need by tweening a movieclip along a path, say over 100 frames using the animation tools (gui), then controlling the contents of the movie clip and the playback of the animation via AS3.

Otherwise you will need to draw your paths in Illustrator or equivalent, export via (e.g.) SVG and import the data. This will work as long as you don't actually need to draw the paths, as, obviously, AS3 can only draw Quadratic Beziers, while Illustrator can only draw/export Cubic Beziers.


You can create array of Point objects, save there all checkpoints of your path. And in a moment when you need nicely show your path. You just need to draw it line by line: line from point 1 to point 2, line from point 2 to point 3.. etc.. Better to do this on some separate Sprite, on top of you map object, so you will be able later to delete it easily from the stage.

In this way you can have arrays of points for every path. The only difficult part here will be to create all these arrays.


If you know the points in the path ahead of time, you could store them in an Array or Vector and handle your drawing manually. Check out the Graphics class for the drawing methods. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html.

If you don't want to go that route, you could apply some code wizardry to do the work for you. One potential way to do it, if you knew the starting point: draw your hidden path on a Shape with a certain color (0x00ff0000, fully transparent red, for example). Then draw your Shape to a BitmapData instance. Each frame, look for fully transparent red pixels adjacent to your current position (using the getPixel method of BitmapData) that you haven't moved to yet, and then move to that point. Note, this technique won't support intersections.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜