views:

48

answers:

1

I have a complex graphics data on a sprite or a shape (no matter which is exactly). But I want to draw shadow (inner too) for one Rect ( [10, 10, 240, 25] for example) or another path.

  /// code before
  grObj.graphics.drawRect( 10, 10, 240, 25);
      /// -> draw inner shadow on this objcect somehow
  /// code after

Is it possible to perform w\o filters?

ps. ht_tp://ipicture.ru/uploads/100927/RHZF1K6Exu.png


solving:

BitmapData(*).applyFilter( *,*,*,*); // play with this function :)

also http://help.adobe.com/ru_RU/AS3LCR/Flash_10.0/flash/display/BitmapData.html#applyFilter()

A: 

i'm assuming you don't want to add filters to your object because you plan on adding a colorTransform and do not want the filters to also change color.

if that's the case what you can do is separate the filter by creating another sprite of the same size as the original, add a drop shadow filter to the new sprite with the hideObject parameter set to true.

//display object
var grObj:Sprite = new Sprite();
grObj.graphics.beginFill(0xFF0000, 1);
grObj.graphics.drawRect(0, 0, 240, 25);
grObj.graphics.endFill();

//filter object
var dsFilter:Sprite = new Sprite();
dsFilter.graphics.beginFill(0);
dsFilter.graphics.drawRect(0, 0, grObj.width, grObj.height);
dsFilter.graphics.endFill();

dsFilter.filters = [new DropShadowFilter(4.0, 45, 0, 1.0, 4.0, 4.0, 1.0, 3, true, false, true)];

//display list
grObj.x = dsFilter.x = 10;
grObj.y = dsFilter.y = 10;

addChild(grObj);
addChild(dsFilter);
TheDarkInI1978
thx for the answer, but I also know such solving. As for me it's too obviously. In my case, I want to draw shadows, or another complex effect on graphisc object w\o neither effects and adding children.
Focker
you could experiment with gradients (grObj.graphics.beginGradientFill()), but i don't think it's possible to create what you want with a gradient. other than that i believe the only other alternative would be to produce your own graphic assets with an external graphics editor and use those assets to create your sprites with a bitmap fill (grObj.graphics.beginBitmapFill()) rather than a regular fill.
TheDarkInI1978
I really interested how far we can go with Matrixes and Gradients...
Focker
out of curiosity, may i ask why you are opposed to using filters?
TheDarkInI1978
filters will cause using the addChild method, but I want to perform drawing on the only one Graphics object. + interesting, of course... If I will not find any applicable decision, I'll be using Filters
Focker
my mind has produced one idea. Create smth (tmp), apply filter, copy tmp's content as BitmapData and then draw it onto desired Shape (Sprite) via beginBitmapFill();
Focker
That's definitely an option, but it is far more computationally expensive to render that the first time. It may make it easier to redraw the output later if the object moves or is recreated from the new Sprite that was bitmapFilled. If there is a real reason for this (you have a sluggish UI), then by all means, your latest idea sounds good, but otherwise, there is no reason not to use filters because your initial UI draw will be more expensive if you don't.
Tegeril
As a decision, now I'm using applyFilter on BitmapData. Works fine!
Focker
@Focker, If this answer solved your problem you should accept the answer (the check sign right under the vote counts)
Colin Hebert
this answer did not solve my problem. Problem was solved by myself. Another problem which is interesting to me is http://stackoverflow.com/questions/3686958/as3-air-load-external-class-from-content-in-another-sandbox
Focker