stage.stageWidth = 560; stage.stageHeight = 400; var distance:uint = 900; //These three paramters are used to control de offset of the normal school var xOff:Number=0,yOff:Number=-150,zOff:Number=0; //This is the sprite which is used to draw the normal school var sprite1:Sprite = new Sprite() Draw(sprite1); stage.addChild(sprite1); //In fact,this sprite has noting to do width this flash,but I just wanna trying some other Drawing APIs,but I used it to let the mouse turn out to be the hand cursor var sprite2:Sprite = new Sprite(); sprite2.graphics.beginFill(0xffffff,0); sprite2.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight); sprite2.graphics.endFill(); sprite2.buttonMode = true; stage.addChild(sprite2); //The following code is used to listen to the three mouseEvent stage.addEventListener(MouseEvent.MOUSE_DOWN,MouseDownHandler); stage.addEventListener(MouseEvent.MOUSE_UP,MouseUpHandler); stage.addEventListener(MouseEvent.MOUSE_WHEEL,MouseWheelHandler); //The following code is the core of this flash; function Draw(sprite:Sprite):void { var x:Number=0,y:Number=300,z:Number=0,zFactor:Number; //drawing the graphic when set the z to be still for(var i:Number=4;i>=-4;i-=0.12) { z = i*70+stage.stageWidth/2+zOff; zFactor = distance/(distance+z); //The following code is used to set the color of the line ,mainly on red var color:uint = Math.round(0xff*zFactor)<<16; if(color>0xff0000) { color = 0xff0000; } sprite.graphics.lineStyle(1,color,1.0,false,LineScaleMode.NONE,CapsStyle.ROUND,JointStyle.ROUND); sprite.graphics.moveTo((-stage.stageWidth/2+xOff)*zFactor,(300+yOff)*zFactor); for(var a:Number=-4;a<=4;a += 0.03) { x = (a*70+xOff)*zFactor; y = (300+yOff - (1200*Math.exp(-0.5*(a*a+i*i))/2)/Math.PI)*zFactor; sprite.graphics.lineTo(x,y); } } //It's important to set this line code ,because the zOff is never unchanged zFactor = distance/(distance+zOff); //The following code is used to drawing the graphic when the x is set to be still for(var i:Number=-4;i<=4;i+=0.12) { x = i*70; sprite.graphics.lineStyle(1,0xff0000,1.0,false,LineScaleMode.NONE,CapsStyle.ROUND,JointStyle.ROUND); sprite.graphics.moveTo((x+xOff)*zFactor,(300+yOff)*zFactor); for(var a:Number=-4;a<=4;a += 0.03) { z = a*70+stage.stageWidth/2+zOff; zFactor = distance/(distance+z); //The following code is used to set the color of the line ,mainly on red var color:uint = Math.round(0xff*zFactor)<<16; if(color>0xff0000) { color = 0xff0000; } //Because the color changes with the z cordinate changes sprite.graphics.lineStyle(1,color,1.0,false,LineScaleMode.NONE,CapsStyle.ROUND,JointStyle.ROUND); tempX = (x+xOff)*zFactor; y = (300+yOff - 1200*Math.exp(-0.5*(a*a+i*i))/2/Math.PI)*zFactor; sprite.graphics.lineTo(tempX,y); } } sprite.x += stage.stageWidth/2; sprite.y += 150; } var preMouseX:uint,preMouseY:uint; function MouseDownHandler(e:MouseEvent):void { preMouseX = e.localX; preMouseY = e.localY; stage.addEventListener(MouseEvent.MOUSE_MOVE,MouseMoveHandler); } function MouseMoveHandler(e:MouseEvent):void { xOff = e.localX - preMouseX; yOff = e.localY - preMouseY-150; //Never forget to recover the sprite in the same place; sprite1.graphics.clear(); sprite1.x -= stage.stageWidth/2; sprite1.y -= 150; Draw(sprite1); } function MouseUpHandler(e:MouseEvent):void { preMouseX = e.localX; preMouseY = e.localY; stage.removeEventListener(MouseEvent.MOUSE_MOVE,MouseMoveHandler); } function MouseWheelHandler(e:MouseEvent):void { zOff += e.delta*10; //Nevet forget to recover the sprite in the same place; sprite1.graphics.clear(); sprite1.x -= stage.stageWidth/2; sprite1.y -= 150; Draw(sprite1); }