views:

301

answers:

1
+2  A: 

Currently it's not possible to introspect the shape of something you drew at design time (i.e. to find out where the corners of all the lines and fills are), so the only good way to draw an outline around an arbitrary shape is as a bitmap effect. However, the way you're going about it is probably not going to be fruitful. Flash gives you a couple of ways to process bitmaps, but anything that involves looping over every pixel usually doesn't wind up being fast enough to use at runtime.

Rather, I'd take one of two approaches: the best and easiest will be to use the built-in filters. As you say, usually when people want to draw an outline, they use a glow filter with a large strength and a short radius. If you want to show only the outline, check the knockout property. (You can do this in script or in the IDE.) If you don't like what you're getting with this, you might try mixing filters - say, adding in a blur before or after the glow. Or you can use code to generate the glow effect into a blank bitmap, and then you can process the result in various ways - for example, with BitmapData.threshold, which I've found is very powerful. Anyway, I'd play with this a while, and make sure it's really not going to solve your problem before you try something else, because it's by far the easiest solution.

The other option is PixelBender. This is a feature that lets you define a custom filter in a C-like language, which you pre-compile and then load into your Flash movie, and apply to the bitmap in question. The process is very similar to programming a photoshop filter. This gives you total control over what kind of processing you want to do to the bitmap, but it requires you to work outside Flash and outside actionscript.

Going your current route and manually processing the pixels is of course a third option, but the question is whether you're really doing anything you couldn't do in a normal or a custom filter. If you really want to finish up what you have going, you might try making a new transparent bitmap, and for every point you captured in the code above, draw a white dot (with setPixel32) at that point. That would give you a pixelated outline, which you'd probably then want to blur, or otherwise process. But really, you're going to wind up with something very similar to what you might have gotten with a normal glow filter, and it will take a lot longer.

fenomas
I'm testing the code that I'm using to get the edges and unless I'm doing something wrong it seems to be pretty speedy. According to Grant Skinner's test harness it runs in 9.63ms or 9631ms for 1000 iterations. I would appreciate if anyone has time to double check that. The code I'm using is here: http://pastebin.com/s59FPGvB
ThunderChunky_SF
Generating the effect in a blank bitmap is probably closest to what I'm after. Would u just apply the transform object from the original bitmap to the blank one? does that even work?
ThunderChunky_SF