views:

13

answers:

1

I have a dropfilter defined using some bindable variables as parameters.

<mx:filters>  
   <mx:DropShadowFilter id="torinofilter" distance="0" color="{dropShadowColor}" 
    blurX="{dropBlur}" blurY="{dropBlur}" strength="8" quality="2" 
    alpha="{dropAlpha}"/>  
</mx:filters>

I would like to update the filter in a method call like this:

this.dropShadowColor = <new color>  
this.dropBlur = 15.0;  
this.dropAlpha = 0.8;

Upon tracing both this.dropShadowColor and torinofilter.color, I see they have updated to the new color, but the color of the dropfilter doesnt change.

I would prefer not to create a new filter because then I get issues with swapChildren.

A: 

Properties of filters cannot be modified like this.

To modify an existing filter object, you must use the technique of modifying a copy of the filters array:

  1. Assign the value of the filters array to a temporary array, such as one named myFilters.
  2. Modify the property by using the temporary array, myFilters. For example, to set the quality property of the first filter in the array, you could use the following code: myFilters[0].quality = 1;
  3. Assign the value of the temporary array to the filters array.

Basically when you read filters array of a DisplayObject, flash returns a copy of the array, not the live filters array. Pushing a new filter or updating existing filters will only modify the copy, not the original; you have to assign it back to the array to reflect the changes.

Do this from actionscript instead of mxml.


I would prefer not to create a new filter because then I get issues with swapChildren.

swapChildren applies only to display objects (UIComponents in case of flex containers).

Amarghosh