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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Filtering display objects<br />

public class ConvolutionFactory ext<strong>en</strong>ds Ev<strong>en</strong>tDispatcher implem<strong>en</strong>ts IFilterFactory<br />

{<br />

// ------- Private vars -------<br />

private var _filter:ConvolutionFilter;<br />

...<br />

// ------- IFilterFactory implem<strong>en</strong>tation -------<br />

public function getFilter():BitmapFilter<br />

{<br />

return _filter;<br />

}<br />

...<br />

}<br />

In the ConvolutionFactory class’s implem<strong>en</strong>tation of the getFilter() method, it returns a ConvolutionFilter<br />

instance, although any object that calls getFilter() doesn’t necessarily know that—according to the definition of the<br />

getFilter() method that ConvolutionFactory follows, it must return any BitmapFilter instance, which could be an<br />

instance of any of the ActionScript filter classes.<br />

Applying filters to display objects<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

As explained previously, the Filter Workb<strong>en</strong>ch application uses an instance of the FilterWorkb<strong>en</strong>chController class<br />

(hereafter referred to as the “controller instance”), which performs the actual task of applying filters to the selected<br />

visual object. Before the controller instance can apply a filter, it first needs to know what image or visual cont<strong>en</strong>t the<br />

filter should be applied to. Wh<strong>en</strong> the user selects an image, the application calls the setFilterTarget() method in<br />

the FilterWorkb<strong>en</strong>chController class, passing in one of the constants defined in the ImageType class:<br />

public function setFilterTarget(targetType:ImageType):void<br />

{<br />

...<br />

_loader = new Loader();<br />

...<br />

_loader.cont<strong>en</strong>tLoaderInfo.addEv<strong>en</strong>tList<strong>en</strong>er(Ev<strong>en</strong>t.COMPLETE, targetLoadComplete);<br />

...<br />

}<br />

Using that information the controller instance loads the designated file, storing it in an instance variable named<br />

_curr<strong>en</strong>tTarget once it loads:<br />

private var _curr<strong>en</strong>tTarget:DisplayObject;<br />

private function targetLoadComplete(ev<strong>en</strong>t:Ev<strong>en</strong>t):void<br />

{<br />

...<br />

_curr<strong>en</strong>tTarget = _loader.cont<strong>en</strong>t;<br />

...<br />

}<br />

Wh<strong>en</strong> the user selects a filter, the application calls the controller instance’s setFilter() method, giving the controller<br />

a refer<strong>en</strong>ce to the relevant filter factory object, which it stores in an instance variable named _filterFactory.<br />

Last updated 6/6/2012<br />

297

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

Saved successfully!

Ooh no, something went wrong!