13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Filtering display objects<br />

// Example of removing a glow filter from a set of filters, where the<br />

//filter you want to remove is the only GlowFilter instance applied<br />

// to the filtered object.<br />

var tempFilters:Array = filteredObject.filters;<br />

// Loop through the filters to find the index of the GlowFilter instance.<br />

var glowIndex:int;<br />

var numFilters:int = tempFilters.l<strong>en</strong>gth;<br />

for (var i:int = 0; i < numFilters; i++)<br />

{<br />

if (tempFilters[i] is GlowFilter)<br />

{<br />

glowIndex = i;<br />

break;<br />

}<br />

}<br />

// Remove the glow filter from the array.<br />

tempFilters.splice(glowIndex, 1);<br />

// Apply the new set of filters to the display object.<br />

filteredObject.filters = tempFilters;<br />

In a more complex case, such as if the filter to remove is selected at runtime, the best approach is to keep a separate,<br />

persist<strong>en</strong>t copy of the filter array that serves as the master list of filters. Any time you make a change to the set of filters,<br />

change the master list th<strong>en</strong> apply that filter array as the filters property of the display object.<br />

For example, in the following code listing, multiple convolution filters are applied to a display object to create differ<strong>en</strong>t<br />

visual effects, and at a later point in the application one of those filters is removed while the others are retained. In this<br />

case, the code keeps a master copy of the filters array, as well as a refer<strong>en</strong>ce to the filter to remove. Finding and<br />

removing the specific filter is similar to the preceding approach, except that instead of making a temporary copy of the<br />

filters array, the master copy is manipulated and th<strong>en</strong> applied to the display object.<br />

Last updated 6/6/2012<br />

273

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!