Flex 돋보기 효과 구현 코드

3544 단어
 
  

layout="vertical"
verticalScrollPolicy="off"
horizontalScrollPolicy="off"
backgroundColor="#FFFFFF"
backgroundGradientColors="#FFFFFF,#FFFFFF"
applicationComplete="onApplicationComplete();"
xmlns:mx="http://www.adobe.com/2006/mxml"
viewSourceURL="srcview/index.html">
<br/>[Embed(source="assets/magnify.pbj", mimeType="application/octet-stream")] <br/>private var shaderObj:Class; <br/>private var shader:Shader; <br/>private var shaderFilter:ShaderFilter; <br/>/** <br/>* Initialize the shader <br/>*/ <br/>private function onApplicationComplete():void <br/>{ <br/>// create the shader <br/>shader = new Shader( new shaderObj() ); <br/>shader.data.center.value = [image.width/2, image.height/2]; <br/>setShader(); <br/>// setup event listeners <br/>stage.addEventListener( Event.ENTER_FRAME, onEnterFrame, false, 0, true ); <br/>} <br/>/** <br/>* Each frame, only reapply the filter if necessary <br/>*/ <br/>private function onEnterFrame( event:Event ):void <br/>{ <br/>setShader(); <br/>} <br/>/** <br/>* Update all the shader's properties, create a new ShaderFilter, <br/>* and reapply it to the image <br/>*/ <br/>private function setShader():void <br/>{ <br/>var centerX:Number = image.mouseX; <br/>var centerY:Number = image.mouseY; <br/>if( centerX &lt; 0 || centerY &lt; 0 || centerX &gt; image.width || centerY &gt; image.height ) <br/>{ <br/>var currentX:Number = shader.data.center.value[0]; <br/>var currentY:Number = shader.data.center.value[1] <br/>centerX = currentX + ((image.width / 2)-currentX) / 2; <br/>centerY = currentY + ((image.height / 2)-currentY) / 2; <br/>} <br/>shader.data.center.value = [centerX, centerY]; <br/>shader.data.innerRadius.value = [innerRadiusSlider.value]; <br/>shader.data.outerRadius.value = [outerRadiusSlider.value]; <br/>shader.data.magnification.value = [magnificationSlider.value]; <br/>shaderFilter = new ShaderFilter( shader ); <br/>image.filters = [shaderFilter]; <br/>} <br/>]]&gt; <br/>


id="innerRadiusSlider"
minimum="0"
maximum="200"
value="50"
liveDragging="true" />


id="outerRadiusSlider"
minimum="0"
maximum="200"
value="100"
liveDragging="true" />


id="magnificationSlider"
minimum="1"
maximum="50"
value="4"
liveDragging="true" />


id="image"
source="assets/YellowFlowers.jpg" />

좋은 웹페이지 즐겨찾기