效果演示:
https://files.cnblogs.com/zhoujunfeng2011/3D%E6%97%8B%E8%BD%AC%E7%9B%B8%E5%86%8C.swf
源码:
主文件:Main.as
package { import flash.display.Sprite; import flash.events.Event; import flash.net.URLRequest; import flash.net.URLLoader; import flash.display.Bitmap; import flash.display.BitmapData; import flash.geom.Point; import flash.display.Shape; import flash.geom.Matrix; import flash.display.GradientType; import flash.events.MouseEvent; import flash.display.DisplayObject; import com.greensock.TweenLite; import com.greensock.easing.*; import ui.*; public class Main extends Sprite { private var num:uint; private var rx:Number = 1300; private var ry:Number = 1; private var pics:Array = new Array(); private var picslength:int; private var speed:Number; private var j:int = -1; private var picw:Number; private var pich:Number; private var picz:int = 2; private var stagew:Number; private var stageh:Number; private var scalex:Number; private var scaley:Number; private var displayobject1:DisplayObject; private var displayobject2:DisplayObject; private var Text:TextFields = new TextFields(); private var clickCount:int = 0; public function Main():void { init(); } private function init():void { var bitmapdata:pic = new pic(); stagew = this.stage.stageWidth / 2; stageh = this.stage.stageHeight / 2; num = 25; for(var i:int =0;i<num;i++) { com(bitmapdata); } stage.addEventListener(Event.ENTER_FRAME,onFrameHandler); } private function com(bmpdt:BitmapData):void { j++; var bitmap:Bitmap = new Bitmap(bmpdt); if ((j == 0)) { picw = bitmap.width; pich = bitmap.height; } var topshape:Shape = new Shape(); var spritecont:Sprite = new Sprite(); addChild(spritecont); DrawInSprite(topshape,bitmap); topshape.x = - picw / 2; topshape.y = - pich / 2; spritecont.addChild(topshape); DrawRef(topshape); spritecont.addEventListener(MouseEvent.ROLL_OVER,roll_over); spritecont.addEventListener(MouseEvent.ROLL_OUT,roll_out); spritecont.addEventListener(MouseEvent.CLICK,mouseclick); var obj:Object = {"spritecont":spritecont,"arg":j * Math.PI * 2 / num}; pics.push(obj); spritecont.x = rx * Math.cos(obj.arg) + stagew; spritecont.y = - ry * Math.sin(obj.arg) + stageh; spritecont.z = 2500; spritecont.scaleX = spritecont.scaleY = spritecont.y - stageh + ry; if ((j == (num - 1))) { picslength = pics.length; } } private function roll_over(evt:MouseEvent):void { if(Text == null) { Text = new TextFields(); } Text.x = - evt.target.width/2; Text.y = 0; Text.time.start(); evt.target.addChild(Text); displayobject1 = evt.target as DisplayObject; scalex = evt.target.scaleX; scaley = evt.target.scaleY; evt.target.parent.setChildIndex(evt.target,evt.target.parent.numChildren - 1); TweenLite.to(evt.target,1,{scaleX:4,scaleY:4,ease:Back.easeOut}); } private function roll_out(evt:MouseEvent):void { Text.time.stop(); evt.target.removeChild(Text); Text = null; displayobject1 = null; displayobject2 = evt.target as DisplayObject; TweenLite.to(evt.target,1,{scaleX:getScale(displayobject2),scaleY:getScale(displayobject2),ease:Back.easeOut,onComplete:onFinishTween}); } private function mouseclick(evt:MouseEvent):void { //待添加... } private function getScale(displayobject:DisplayObject):Number { if (Math.abs(speed) >= 0.04) { return 0; } else { return displayobject.y - stageh + ry; } } private function onFinishTween():void { displayobject2 = null; } private function DrawRef(p_source:DisplayObject):void { //对源显示对象做上下反转处理 var bd:BitmapData = new BitmapData(p_source.width,p_source.height,true,0); var mtx:Matrix = new Matrix(); mtx.d = -1; mtx.ty = bd.height; bd.draw(p_source,mtx); //生成一个渐变遮罩 var width:int = bd.width; var height:int = bd.height; mtx = new Matrix(); mtx.createGradientBox(width,height,0.5 * Math.PI); var shape:Shape = new Shape(); shape.graphics.beginGradientFill(GradientType.LINEAR,[0xff0000,0xff0000],[0.5,0],[0,255],mtx); shape.graphics.drawRect(0,0,width,height); shape.graphics.endFill(); var mask_bd:BitmapData = new BitmapData(width,height,true,0); mask_bd.draw(shape); //生成最终效果; bd.copyPixels(bd,bd.rect,new Point(0,0),mask_bd,new Point(0,0),false); //将倒影位图放在源显示对象下面 var ref:Bitmap = new Bitmap(); ref.x = p_source.x; ref.y = p_source.height / 2; ref.bitmapData = bd; p_source.parent.addChild(ref); } private function DrawInSprite(shape:Shape,bitmap:Bitmap):void { shape.graphics.lineStyle(7,0xffffff); shape.graphics.beginBitmapFill(bitmap.bitmapData); shape.graphics.drawRect(0,0,picw,pich); shape.graphics.endFill(); } private function onFrameHandler(evt:Event):void { speed = (this.mouseX - stagew)/5000; refreshIndex(); refreshPosition(); } private function refreshIndex():void { var gap:int = 1; var left:int = 0; var right:int = 0; var temp:Object; while ((gap <= picslength / 3)) { gap = gap * 3 + 1; } while ((gap > 0)) { for (right = gap; right < picslength; right++) { temp = pics[right]; left = right; if (this.displayobject1 != pics[right]["spritecont"]) { while (((left > gap - 1) && Number(pics[left - gap]["spritecont"].y) >= Number(temp["spritecont"].y))) { pics[left] = pics[left - gap]; left -= gap; } pics[left] = temp; } } gap = (gap - 1) / 3; } } private function refreshPosition():void { for (var i:int = 0; i < picslength; i++) { var obj:Object = pics[i]; var spritecont:Sprite = obj.spritecont as Sprite; obj.arg += speed; spritecont.x = rx * Math.cos(obj.arg) + stagew; spritecont.y = - ry * Math.sin(obj.arg) + stageh; if (this.displayobject1 != spritecont && this.displayobject2 != spritecont) { spritecont.parent.setChildIndex(spritecont,i); spritecont.scaleX = spritecont.scaleY = spritecont.y - stageh + ry; } if (this.displayobject2) { this.displayobject2.parent.setChildIndex(this.displayobject2,this.displayobject2.parent.numChildren-1); } if (this.displayobject1) { this.displayobject1.parent.setChildIndex(this.displayobject1,this.displayobject1.parent.numChildren-1); } } } } }
ui包中的类:
package ui { import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFormat; import flash.text.TextFieldAutoSize; import flash.filters.BitmapFilter; import flash.filters.BitmapFilterQuality; import flash.filters.GlowFilter; import com.greensock.TweenLite; import flash.utils.Timer; import flash.events.TimerEvent; public class TextFields extends Sprite { private var Text:String = "点击放大(未实现)"; private var txt:TextField = new TextField(); public var time:Timer = new Timer(1000); public function TextFields():void { CreateLineStyleOrText(); } private function CreateLineStyleOrText():void { var format:TextFormat = new TextFormat(); format.font = "Verdana"; format.color = 0xffffff; format.bold = true; format.size = 15; txt.text = Text; txt.border = true; txt.borderColor = 0xffffff; txt.autoSize = TextFieldAutoSize.CENTER; txt.selectable = false; txt.setTextFormat(format); CreateTextFilter(txt); time.addEventListener(TimerEvent.TIMER,timeHanlder); addChild(txt); } private function CreateTextFilter(Text:TextField):void { var filter:BitmapFilter = getBitmapFilter(); var myfilters:Array = new Array(); myfilters.push(filter); Text.filters = myfilters; } private function timeHanlder(evt:TimerEvent):void { TweenLite.to(txt,0.5,{alpha:0,onComplete:onFinishTween}); } private function onFinishTween():void { TweenLite.to(txt,0.5,{alpha:0.8}); } private function getBitmapFilter():BitmapFilter { return new GlowFilter(0x33ccff,0.8,5,5,2,BitmapFilterQuality.HIGH,false,false); } } }
package ui { import flash.display.BitmapData; public class pic extends BitmapData { public function pic() { super(0,0); } } }
还有一个第三方缓动类:greensock,可去网上下载!