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 />

yMap.dispose();<br />

// Display the map image on the Stage, for refer<strong>en</strong>ce.<br />

var mapBitmap:Bitmap = new Bitmap(map);<br />

this.addChild(mapBitmap);<br />

mapBitmap.x = 400;<br />

mapBitmap.y = stage.stageHeight - mapBitmap.height;<br />

// This function creates the displacem<strong>en</strong>t map filter at the mouse location.<br />

function magnify():void<br />

{<br />

// Position the filter.<br />

var filterX:Number = (loader.mouseX) - (map.width / 2);<br />

var filterY:Number = (loader.mouseY) - (map.height / 2);<br />

var pt:Point = new Point(filterX, filterY);<br />

var xyFilter:Displacem<strong>en</strong>tMapFilter = new Displacem<strong>en</strong>tMapFilter();<br />

xyFilter.mapBitmap = map;<br />

xyFilter.mapPoint = pt;<br />

// The red in the map image will control x displacem<strong>en</strong>t.<br />

xyFilter.compon<strong>en</strong>tX = BitmapDataChannel.RED;<br />

// The blue in the map image will control y displacem<strong>en</strong>t.<br />

xyFilter.compon<strong>en</strong>tY = BitmapDataChannel.BLUE;<br />

xyFilter.scaleX = 35;<br />

xyFilter.scaleY = 35;<br />

xyFilter.mode = Displacem<strong>en</strong>tMapFilterMode.IGNORE;<br />

loader.filters = [xyFilter];<br />

}<br />

// This function is called wh<strong>en</strong> the mouse moves. If the mouse is<br />

// over the loaded image, it applies the filter.<br />

function moveMagnifier(ev<strong>en</strong>t:MouseEv<strong>en</strong>t):void<br />

{<br />

if (loader.hitTestPoint(loader.mouseX, loader.mouseY))<br />

{<br />

magnify();<br />

}<br />

}<br />

loader.addEv<strong>en</strong>tList<strong>en</strong>er(MouseEv<strong>en</strong>t.MOUSE_MOVE, moveMagnifier);<br />

Last updated 6/6/2012<br />

290

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

Saved successfully!

Ooh no, something went wrong!