View Full Version : Convert a Line to a Fill using Code
themortalgod
06-17-2008, 04:27 PM
ok so I am trying to draw a curve and then make it into a mask, the problem is, flash only calculates the mask for a fill and thus using the line does not work. Does anyone know of a way to convert a line to a fill with as3 without using something like bitmap data as I would like to keep it as vector data if possible, below is my code:
line = new Sprite();
this.addChild(line);
line.graphics.lineStyle(6,0xFFFFFF);
line.graphics.moveTo(planetX,planetY);
line.graphics.curveTo(planetX,_mom.gsh(),_mom.gsw( ),_mom.gsh()-30);
art.mask = line;
if I add a beginFill to the line, the mask works fine (but it masks the fill which i dont want)
thx in advance for any help
ScreamingKettle
07-16-2008, 11:15 AM
Bump!
Does anyone yet know the answer? I tried converting a MovieClip, with just a diagonal line in it, into a Bitmap (via drawing BitmapData from it) and using that as the mask for something, as I think themortalgod was implying. However, this just created a rectangular mask the size of the Bitmap, regardless of what was actually in the Bitmap.
senocular
07-16-2008, 11:32 AM
You can't convert lines to fills in code. You'd have to draw a fill instead of the line. Straight lines are usually pretty easy (drawing rectangles) but curves can be a little more complicated for good results (the outer curveTo needing to be slightly larger than the inner).
This bitmap approach is probably easiest. Though you'll have to make sure your maskee is cached as bitmap for it to work
danniedarko
02-03-2009, 05:55 AM
Maybe it's a little late, but I've stumbled over the same problem.
I thought in order to help others with the same prob I'll post it anyway.
My solution is simply to achieve the bitmap caching through actionscript.
Simply add the following
theMaskee.cacheAsBitmap=true;
theMask.cacheAsBitmap=true;
and the masking will work without having to use any fills. Simply use graphics.lineTo i.e. and you'll get the desired results.
In your case it should work like this
art.cacheAsBitmap=true;
line = new Shape();
line.cacheAsBitmap=true;
line.graphics.lineStyle(6,0xFFFFFF);
line.graphics.moveTo(planetX,planetY);
line.graphics.curveTo(planetX,_mom.gsh(),_mom.gsw( ),_mom.gsh()-30);
this.addChild(line);
art.mask = line;
So long,
Dannie
ScreamingKettle
02-03-2009, 08:17 AM
Ahhh bonza :)
Thanks for a final answer to this. Now I just have to remember what I needed it for...
forbletons
03-15-2011, 01:02 PM
Spent absolutely ages trying to find a way of making my dynamically generated line mask something.
+1 Karma points to you!
Thanks
Andy
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.