flash特效原理 CoverFlow 效果 2

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.****.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

flash特效原理 CoverFlow 效果 2

 

 

   今晚抽点时间记录一下coverFlow效果。前几天修改了一个coverFlow的效果的代码。看到coverFlow效果有一种比较有趣的思路去制作。

 

在创造这个特效过程当中,所涉及到一些类包含缓冲类,包括倒影类,同时也可以使用一种数据结构来实现左右移动的时候变化,思路可以借鉴一下。

 

在这里大概讲解一下制作过程。

制作原理:我们可以看到图片都在Y轴都偏移了一定的角度,并且每一张图片都保持一定的距离。在交互的时候,中间的图片会进行滑行放大,由原来的偏移角度从(angle-->0)进行变化,并且在位置上都移动到另外一个位置。(x1-->x2)所以在这个动画过程当中,有两个属性发生变化了。

 

             (角度--->0)

              (位置X-->变化到另外一个位置)

 

 在每次点击一张图片,那么这张图片如果在目标图片的左边,那么左边所有图片(photo1,photo2....)会向右进行位置移动

                                                  如果在目标图片的右边,那么左边所有图片(photo5,photo6....)会向左进行位置移动

 

 

懂了这个我们可以尝试制作一下。

 

 

一。图形的线性分布

我们首先会依据这些图片按一定间距进行分布,这样看起来就像一条线。随后,我们将下面的图片按一定角度Y轴进行偏移,这样就能像coverflow的效果。看起来会有一点摸样了。

 flash特效原理 CoverFlow 效果 2

 

 

flash特效原理 CoverFlow 效果 2

 

 

二 交互

  在flash 交互过程当中,图片进行滑动并且将原先的偏移的角度变化到一个角度。在这个过程当中,我们使用缓冲的类产生这个过程。

一方面改变这种偏移角度变化,一方面改变位置变化,在这个过程当中你会发现你点击的图片,和其他图片都会发生改变移动,这也是这个交互比较有趣的地方,我们可以通过循环检测目标图片左边的图片和右边的图片。并让其发生改变。那么这个交互就已经可以把握到了。

 

如:

A1 A2 A3(目标图片)B1 B2 B3

 

 

 

[c-sharp] view plain copy print?
  1. package   
  2. {  
  3.     import flash.display.*;  
  4.     import flash.net.*;  
  5.     import flash.events.*;    
  6.     import org.summerTree.effect.CoverFlow;  
  7.     import org.summerTree.effect.Image;  
  8.     import org.summerTree.effect.Reflection;  
  9.     public class Main extends Sprite  
  10.     {  
  11.         private var coverflow:CoverFlow=new CoverFlow();//创建coverFlow效果类       
  12.         public function Main()  
  13.         {  
  14.               
  15.             coverflow.SPACING=80;//设置间距  
  16.               
  17.             addChild(coverflow);  
  18.             coverflow.move(stage.stageWidth/2,stage.stageHeight/2);               
  19.             coverflow.addEventListener(Event.COMPLETE,onLoadCompleteHandler);  
  20.             coverflow.loadImage("image/0.jpg","image/1.jpg","image/2.jpg",  
  21.                                  "image/3.jpg","image/4.jpg",  
  22.                                  "image/5.jpg","image/6.jpg",  
  23.                                  "image/7.jpg","image/8.jpg",  
  24.                                  "image/9.jpg","image/10.jpg"  
  25.                                    
  26.                                  ); //加载图片            
  27.         }  
  28.           
  29.         private function onLoadCompleteHandler(event:Event):void  
  30.         {  
  31.             coverflow.removeEventListener(Event.COMPLETE,onLoadCompleteHandler);  
  32.             creatSprite(coverflow.imageArray);  
  33.             coverflow.addListener();//添加左右按键              
  34.         }  
  35.                       
  36.         //创建图形  
  37.         private function creatSprite(array:Array):void  
  38.         {  
  39.             var n:int=array.length;  
  40.             for (var i:int=0; i<n; i++)  
  41.             {  
  42.                 var image:Image=array[i];  
  43.                 var refect:Reflection=new Reflection(image,255,Reflection.CENTER,0.7,0.6);//对图片产生倒影效果  
  44.                 image.addEventListener(MouseEvent.CLICK,onClickHandler);  
  45.                 coverflow.addImage(image);//添加图片               
  46.             }  
  47.               
  48.             coverflow.flow(array[int(n/2)]);  
  49.         }  
  50.               
  51.         private function onClickHandler(event:MouseEvent):void  
  52.         {  
  53.             var image:Image = event.currentTarget as Image;  
  54.             coverflow.flow(image);  
  55.         }  
  56.   
  57.     }  
  58. }  
package { import flash.display.*; import flash.net.*; import flash.events.*;  import org.summerTree.effect.CoverFlow; import org.summerTree.effect.Image; import org.summerTree.effect.Reflection; public class Main extends Sprite {  private var coverflow:CoverFlow=new CoverFlow();//创建coverFlow效果类    public function Main()  {      coverflow.SPACING=80;//设置间距      addChild(coverflow);   coverflow.move(stage.stageWidth/2,stage.stageHeight/2);       coverflow.addEventListener(Event.COMPLETE,onLoadCompleteHandler);   coverflow.loadImage("image/0.jpg","image/1.jpg","image/2.jpg",         "image/3.jpg","image/4.jpg",         "image/5.jpg","image/6.jpg",         "image/7.jpg","image/8.jpg",         "image/9.jpg","image/10.jpg"                  ); //加载图片     }    private function onLoadCompleteHandler(event:Event):void  {   coverflow.removeEventListener(Event.COMPLETE,onLoadCompleteHandler);   creatSprite(coverflow.imageArray);   coverflow.addListener();//添加左右按键     }       //创建图形  private function creatSprite(array:Array):void  {   var n:int=array.length;   for (var i:int=0; i<n; i++)   {    var image:Image=array[i];    var refect:Reflection=new Reflection(image,255,Reflection.CENTER,0.7,0.6);//对图片产生倒影效果    image.addEventListener(MouseEvent.CLICK,onClickHandler);    coverflow.addImage(image);//添加图片       }      coverflow.flow(array[int(n/2)]);  }     private function onClickHandler(event:MouseEvent):void  {   var image:Image = event.currentTarget as Image;   coverflow.flow(image);  } }}

 

 

   CoverFlow.as

[c-sharp] view plain copy print?
  1. package org.summerTree.effect  
  2. {  
  3.   
  4.     import flash.display.Sprite;  
  5.     import flash.events.*;  
  6.     import org.summerTree.datastruct.DLinkedList;  
  7.     import org.summerTree.datastruct.DLinkNode;  
  8.     import com.greensock.TweenLite;  
  9.     import flash.display.Loader;  
  10.     import flash.net.URLRequest;  
  11.     import flash.display.Bitmap;  
  12.     import flash.display.BitmapData;  
  13.     import flash.ui.*;  
  14.   
  15.     public class CoverFlow extends Sprite  
  16.     {  
  17.         public var TIME:Number = 0.5;//移动响应时间  
  18.         public var ROTATION_Y:Number = 60;//偏转角度  
  19.         public var SPACING:Number = 100;//图片之间间隔  
  20.         public var Z_FOCUS:int = -300;//z深度  
  21.         private var targetImage:Image;//图片目标  
  22.         private var plane:Image;  
  23.         private var image_size:int = 0;  
  24.         private var _imageArray:Array = [];  
  25.         private var planeList:DLinkedList = new DLinkedList();  
  26.         public function CoverFlow()  
  27.         {  
  28.   
  29.   
  30.         }  
  31.   
  32.         //添加图片  
  33.         public function addImage(image:Image):void  
  34.         {  
  35.             planeList.appendNode(image);  
  36.             this.addChild(image);  
  37.         }  
  38.   
  39.         //加载图片  
  40.         public function loadImage(...args):void  
  41.         {  
  42.             var len:int = args.length;  
  43.             image_size = len;  
  44.             for (var i:int=0; i<len; i++)  
  45.             {  
  46.                 var loader:Loader=new Loader();  
  47.                 loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadCompleteHandler);  
  48.                 loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onErrorHandler);  
  49.                 loader.load(new URLRequest(args[i]));  
  50.             }  
  51.   
  52.         }  
  53.   
  54.         private function onErrorHandler(event:IOErrorEvent):void  
  55.         {  
  56.             throw new Error("发生错误");  
  57.         }  
  58.   
  59.         private function onLoadCompleteHandler(event:Event):void  
  60.         {  
  61.             event.currentTarget.addEventListener(Event.COMPLETE,onLoadCompleteHandler);  
  62.             var image:Bitmap = event.currentTarget.content;  
  63.             _imageArray.push(new Image(image));  
  64.             image.bitmapData.dispose();  
  65.             image_size--;  
  66.             if (image_size == 0)  
  67.             {  
  68.                 this.dispatchEvent(new Event(Event.COMPLETE));  
  69.             }  
  70.   
  71.         }  
  72.   
  73.         public function get imageArray():Array  
  74.         {  
  75.             return _imageArray;  
  76.         }  
  77.   
  78.   
  79.         public function move(x:Number,y:Number):void  
  80.         {  
  81.             this.x = x;  
  82.             this.y = y;  
  83.         }  
  84.   
  85.         //监听鼠标和键盘监听   
  86.         public function addListener():void  
  87.         {  
  88.             stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDownHandler);  
  89.             stage.addEventListener(MouseEvent.MOUSE_WHEEL,onWheelHandler);  
  90.         }  
  91.   
  92.         //跟随  
  93.         public function flow(plane:Image):void  
  94.         {  
  95.             var xPosition:Number = 0;  
  96.             targetImage = plane;  
  97.             TweenLite.to(plane, TIME, {x:xPosition, z:Z_FOCUS, rotationY:0});  
  98.             var current:DLinkNode = planeList.nodeOf(plane);//搜索当前节点  
  99.   
  100.             var walkLeft:DLinkNode = current.preNode;  
  101.             while (walkLeft)  
  102.             {  
  103.                 plane = Image(walkLeft.data);  
  104.                 xPosition -=  SPACING;  
  105.                 TweenLite.to(plane, TIME, {x:xPosition, z:0, rotationY:-ROTATION_Y});  
  106.                 walkLeft = walkLeft.preNode;  
  107.                 this.setChildIndex(plane,0);  
  108.             }  
  109.   
  110.             xPosition = 0;  
  111.             var walkRight:DLinkNode = current.nextNode;  
  112.             while (walkRight)  
  113.             {  
  114.                 plane = Image(walkRight.data);  
  115.                 xPosition +=  SPACING;  
  116.                 TweenLite.to(plane, TIME, {x:xPosition, z:0, rotationY:ROTATION_Y});  
  117.                 this.setChildIndex(plane,0);  
  118.                 walkRight = walkRight.nextNode;  
  119.             }  
  120.         }  
  121.   
  122.   
  123.         public function preview():void  
  124.         {  
  125.             if (planeList.nodeOf(targetImage).preNode != null)  
  126.             {  
  127.                 plane = planeList.nodeOf(targetImage).preNode.data as Image;  
  128.                 flow(plane);  
  129.             }  
  130.   
  131.         }  
  132.   
  133.         public function next():void  
  134.         {  
  135.             if (planeList.nodeOf(targetImage).nextNode != null)  
  136.             {  
  137.                 plane = planeList.nodeOf(targetImage).nextNode.data as Image;  
  138.                 flow(plane);  
  139.             }  
  140.         }  
  141.   
  142.         // 左右键盘  
  143.         private function onKeyDownHandler(event:KeyboardEvent):void  
  144.         {  
  145.             if (event.keyCode == Keyboard.RIGHT)  
  146.             {  
  147.                 next();  
  148.   
  149.             }  
  150.             else if (event.keyCode==Keyboard.LEFT)  
  151.             {  
  152.                 preview();  
  153.             }  
  154.   
  155.         }  
  156.   
  157.         //鼠标滚动  
  158.         private function onWheelHandler(event:MouseEvent):void  
  159.         {  
  160.             if (event.delta > 0)  
  161.             {  
  162.   
  163.                 preview();  
  164.             }  
  165.             else  
  166.             {  
  167.                 next();  
  168.             }  
  169.         }  
  170.     }  
  171. }  
package org.summerTree.effect{ import flash.display.Sprite; import flash.events.*; import org.summerTree.datastruct.DLinkedList; import org.summerTree.datastruct.DLinkNode; import com.greensock.TweenLite; import flash.display.Loader; import flash.net.URLRequest; import flash.display.Bitmap; import flash.display.BitmapData; import flash.ui.*; public class CoverFlow extends Sprite {  public var TIME:Number = 0.5;//移动响应时间  public var ROTATION_Y:Number = 60;//偏转角度  public var SPACING:Number = 100;//图片之间间隔  public var Z_FOCUS:int = -300;//z深度  private var targetImage:Image;//图片目标  private var plane:Image;  private var image_size:int = 0;  private var _imageArray:Array = [];  private var planeList:DLinkedList = new DLinkedList();  public function CoverFlow()  {  }  //添加图片  public function addImage(image:Image):void  {   planeList.appendNode(image);   this.addChild(image);  }  //加载图片  public function loadImage(...args):void  {   var len:int = args.length;   image_size = len;   for (var i:int=0; i<len; i++)   {    var loader:Loader=new Loader();    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadCompleteHandler);    loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onErrorHandler);    loader.load(new URLRequest(args[i]));   }  }  private function onErrorHandler(event:IOErrorEvent):void  {   throw new Error("发生错误");  }  private function onLoadCompleteHandler(event:Event):void  {   event.currentTarget.addEventListener(Event.COMPLETE,onLoadCompleteHandler);   var image:Bitmap = event.currentTarget.content;   _imageArray.push(new Image(image));   image.bitmapData.dispose();   image_size--;   if (image_size == 0)   {    this.dispatchEvent(new Event(Event.COMPLETE));   }  }  public function get imageArray():Array  {   return _imageArray;  }  public function move(x:Number,y:Number):void  {   this.x = x;   this.y = y;  }  //监听鼠标和键盘监听   public function addListener():void  {   stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDownHandler);   stage.addEventListener(MouseEvent.MOUSE_WHEEL,onWheelHandler);  }  //跟随  public function flow(plane:Image):void  {   var xPosition:Number = 0;   targetImage = plane;   TweenLite.to(plane, TIME, {x:xPosition, z:Z_FOCUS, rotationY:0});   var current:DLinkNode = planeList.nodeOf(plane);//搜索当前节点   var walkLeft:DLinkNode = current.preNode;   while (walkLeft)   {    plane = Image(walkLeft.data);    xPosition -=  SPACING;    TweenLite.to(plane, TIME, {x:xPosition, z:0, rotationY:-ROTATION_Y});    walkLeft = walkLeft.preNode;    this.setChildIndex(plane,0);   }   xPosition = 0;   var walkRight:DLinkNode = current.nextNode;   while (walkRight)   {    plane = Image(walkRight.data);    xPosition +=  SPACING;    TweenLite.to(plane, TIME, {x:xPosition, z:0, rotationY:ROTATION_Y});    this.setChildIndex(plane,0);    walkRight = walkRight.nextNode;   }  }  public function preview():void  {   if (planeList.nodeOf(targetImage).preNode != null)   {    plane = planeList.nodeOf(targetImage).preNode.data as Image;    flow(plane);   }  }  public function next():void  {   if (planeList.nodeOf(targetImage).nextNode != null)   {    plane = planeList.nodeOf(targetImage).nextNode.data as Image;    flow(plane);   }  }  // 左右键盘  private function onKeyDownHandler(event:KeyboardEvent):void  {   if (event.keyCode == Keyboard.RIGHT)   {    next();   }   else if (event.keyCode==Keyboard.LEFT)   {    preview();   }  }  //鼠标滚动  private function onWheelHandler(event:MouseEvent):void  {   if (event.delta > 0)   {    preview();   }   else   {    next();   }  } }}

 

 

[c-sharp] view plain copy print?
  1. package org.summerTree.effect  
  2. {  
  3.     import flash.display.Sprite;  
  4.     import flash.display.Bitmap;  
  5.     import flash.display.BitmapData;  
  6.       
  7.     public class Image extends Sprite  
  8.     {  
  9.           
  10.         public var url:String;  
  11.         public function Image(source:*)  
  12.         {  
  13.             var bmpData:BitmapData=new BitmapData(source.width,source.height,false,0x0);  
  14.             bmpData.draw(source);  
  15.             var bitmap:Bitmap=new Bitmap(bmpData);  
  16.             bitmap.x-=bitmap.width/2;  
  17.             bitmap.y-=bitmap.height/2;  
  18.             addChild(bitmap);  
  19.         }  
  20.     }  
  21.   
  22. }  
package org.summerTree.effect{ import flash.display.Sprite; import flash.display.Bitmap; import flash.display.BitmapData;  public class Image extends Sprite {    public var url:String;  public function Image(source:*)  {   var bmpData:BitmapData=new BitmapData(source.width,source.height,false,0x0);   bmpData.draw(source);   var bitmap:Bitmap=new Bitmap(bmpData);   bitmap.x-=bitmap.width/2;   bitmap.y-=bitmap.height/2;   addChild(bitmap);  } }}

 

 

 

[c-sharp] view plain copy print?
  1. package org.summerTree.datastruct  
  2. {  
  3.   
  4.     public class DLinkNode  
  5.     {  
  6.         public var data:*;  
  7.         public var preNode:DLinkNode;  
  8.         public var nextNode:DLinkNode;  
  9.         public function DLinkNode(obj:*)  
  10.         {  
  11.             preNode = nextNode = null;  
  12.             data = obj;  
  13.         }  
  14.     }  
  15.   
  16. }  
package org.summerTree.datastruct{ public class DLinkNode {  public var data:*;  public var preNode:DLinkNode;  public var nextNode:DLinkNode;  public function DLinkNode(obj:*)  {   preNode = nextNode = null;   data = obj;  } }}

 

 

[c-sharp] view plain copy print?
  1. package org.summerTree.datastruct  
  2. {  
  3.     import org.summerTree.datastruct.DLinkNode;  
  4.     public class DLinkedList  
  5.     {  
  6.         private var _size:int = 0;  
  7.         public var head:DLinkNode = null;//头节点  
  8.         public var tail:DLinkNode = null;//尾节点  
  9.         private var NodeList:Array=[];  
  10.         public function DLinkedList()  
  11.         {  
  12.   
  13.         }  
  14.   
  15.         //插入节点  
  16.         public function appendNode(obj: * ):void  
  17.         {  
  18.             var newNode:DLinkNode = new DLinkNode(obj);  
  19.             if (this.isEmpty())  
  20.             {  
  21.                 head = newNode;  
  22.             }  
  23.             else  
  24.             {  
  25.                 tail.nextNode = newNode;  
  26.                 newNode.preNode = tail;  
  27.             }  
  28.             tail = newNode;  
  29.             _size++;  
  30.             NodeList.push(newNode);  
  31.         }  
  32.   
  33.   
  34.         //搜索当前节点  
  35.         public function nodeOf(obj: * ):DLinkNode  
  36.         {   
  37.             var len:int=NodeList.length;  
  38.             for(var i:int=0;i<len;i++)  
  39.             {  
  40.                 if(NodeList[i].data==obj)  
  41.                 {  
  42.                     //break;  
  43.                     return NodeList[i];  
  44.                       
  45.                 }                 
  46.             }  
  47.               
  48.             return null;  
  49.         }  
  50.   
  51.         //判断是否空链表  
  52.         public function isEmpty():Boolean  
  53.         {  
  54.             return size == 0;  
  55.         }  
  56.           
  57.         //返回节点数   
  58.         public function get size():int  
  59.         {  
  60.             return _size;  
  61.         }  
  62.     }  
  63.   
  64. }  
package org.summerTree.datastruct{ import org.summerTree.datastruct.DLinkNode; public class DLinkedList {  private var _size:int = 0;  public var head:DLinkNode = null;//头节点  public var tail:DLinkNode = null;//尾节点  private var NodeList:Array=[];  public function DLinkedList()  {  }  //插入节点  public function appendNode(obj: * ):void  {   var newNode:DLinkNode = new DLinkNode(obj);   if (this.isEmpty())   {    head = newNode;   }   else   {    tail.nextNode = newNode;    newNode.preNode = tail;   }   tail = newNode;   _size++;   NodeList.push(newNode);  }  //搜索当前节点  public function nodeOf(obj: * ):DLinkNode  {       var len:int=NodeList.length;   for(var i:int=0;i<len;i++)      {    if(NodeList[i].data==obj)    {     //break;     return NodeList[i];         }       }      return null;  }  //判断是否空链表  public function isEmpty():Boolean  {   return size == 0;  }          //返回节点数   public function get size():int  {   return _size;  } }}

 

 

[c-sharp] view plain copy print?
  1. package org.summerTree.effect  
  2. {  
  3.     //倒影类  
  4.     import flash.display.*;  
  5.     import flash.geom.*;  
  6.   
  7.     public class Reflection    
  8.     {  
  9.         private var reflectionContainer:DisplayObjectContainer;  
  10.         private var reflectionHeight:Number;  
  11.         private var reflectionalphaStrength:Number;//透明度  
  12.         private var reflectionPercent:Number;  
  13.         private var offDistance:Number;//偏移距离  
  14.         private var reflectionClip:Sprite;  
  15.           
  16.         private var reflectionBMP:Bitmap;//倒影位图  
  17.         private var reflectionMask:Sprite;//倒影遮罩  
  18.         private var RegPointType:String;//注册点位置类型  
  19.           
  20.         //实现三种情况进行倒影  
  21.         public static var LEFT_TOP:String="left_top";  
  22.         public static var CENTER:String="center";  
  23.         public static var CENTER_BOTTOM:String="center_bottom";  
  24.           
  25.   
  26.         /* @ para reflectionContainer 倒影的容器 
  27.          * @ para reflectionHeight  倒影高度 
  28.          * @ para RegPointType  注册点类型,根据不同注册点位置做出相应的倒影 
  29.          * @ para alphaStrength 透明度 (0-1) 
  30.          * @ para reflectionPercent 倒影映射的百分比 
  31.          * @ para offDistance 偏移距离 
  32.          */  
  33.          
  34.         public function Reflection(reflectionContainer:DisplayObjectContainer, reflectionHeight:Number = 255, RegPointType:String="left_top" ,alphaStrength:Number = 1, reflectionPercent:Number = -1 ,offDistance:Number=0)  
  35.         {  
  36.             this.reflectionContainer = reflectionContainer;  
  37.             this.reflectionHeight = reflectionHeight;  
  38.             this.reflectionalphaStrength = alphaStrength;  
  39.             this.reflectionPercent = reflectionPercent;  
  40.             this.RegPointType=RegPointType;  
  41.             this.offDistance=offDistance;  
  42.             CreatReflection();  
  43.             addItem();  
  44.         }  
  45.          
  46.         //创建倒影  
  47.         private function CreatReflection():void  
  48.         {  
  49.             reflectionClip = new Sprite();//倒影剪辑容器  
  50.             reflectionMask = new Sprite();//遮罩  
  51.               
  52.             var bmd:BitmapData = new BitmapData(reflectionContainer.width,reflectionContainer.height,true,0xffffff);  
  53.             if(RegPointType==Reflection.LEFT_TOP)  
  54.             {  
  55.                 bmd.draw(reflectionContainer);  
  56.                 reflectionBMP = new Bitmap(bmd);  
  57.                 reflectionBMP.scaleY= -1;  
  58.                 reflectionBMP.x = 0;  
  59.                 reflectionBMP.y = reflectionBMP.height*2+offDistance;  
  60.                 reflectionMask.y = reflectionBMP.height+offDistance;  
  61.                 reflectionMask.x = 0;  
  62.             }  
  63.             else if(RegPointType==Reflection.CENTER)  
  64.             {  
  65.                 var matrix:Matrix=new Matrix();  
  66.                 matrix.tx=reflectionContainer.width/2;  
  67.                 matrix.ty=reflectionContainer.height/2;  
  68.                 bmd.draw( reflectionContainer,matrix);  
  69.                 reflectionBMP = new Bitmap(bmd);  
  70.                 reflectionBMP.scaleY= -1;  
  71.                 reflectionBMP.x = -reflectionBMP.width/2;  
  72.                 reflectionBMP.y = reflectionBMP.height+reflectionBMP.height/2+offDistance;  
  73.                 reflectionMask.y = reflectionBMP.height/2+offDistance;  
  74.                 reflectionMask.x = -reflectionBMP.width/2;  
  75.             }  
  76.             else if(RegPointType==Reflection.CENTER_BOTTOM)  
  77.             {  
  78.                 var matrixB:Matrix=new Matrix();  
  79.                 matrixB.tx=reflectionContainer.width/2;  
  80.                 matrixB.ty=reflectionContainer.height;            
  81.                 bmd.draw( reflectionContainer,matrixB);  
  82.                 reflectionBMP = new Bitmap(bmd);  
  83.                 reflectionBMP.scaleY= -1;  
  84.                 reflectionBMP.x = -reflectionBMP.width/2;  
  85.                 reflectionBMP.y = reflectionBMP.height+offDistance;  
  86.                 reflectionMask.y = 0+offDistance;  
  87.                 reflectionMask.x = -reflectionBMP.width/2;  
  88.             }  
  89.                   
  90.             var fillType:String = GradientType.LINEAR;  
  91.             var colors:Array = [0xFFFFFF,0xFFFFFF];  
  92.             var alphas:Array = [reflectionalphaStrength,0];  
  93.             var ratios:Array = [0,reflectionHeight];  
  94.             var matr:Matrix = new Matrix();  
  95.             var matrixHeight:Number;  
  96.             if(reflectionPercent<=0)  
  97.             {  
  98.                 matrixHeight=reflectionContainer.height;  
  99.             }  
  100.             else  
  101.             {  
  102.                 matrixHeight=reflectionContainer.height*reflectionPercent;  
  103.             }  
  104.             var spreadMethod:String = SpreadMethod.PAD;  
  105.   
  106.             matr.createGradientBox(reflectionContainer.width ,matrixHeight, 0.5*Math.PI,0, 0);  
  107.             reflectionMask.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);  
  108.             reflectionMask.graphics.drawRect(0, 0, reflectionContainer.width, reflectionContainer.height);  
  109.             reflectionMask.graphics.endFill();  
  110.           
  111.             reflectionBMP.cacheAsBitmap = true;  
  112.             reflectionMask.cacheAsBitmap = true;  
  113.             reflectionBMP.mask = reflectionMask;  
  114.         }  
  115.   
  116.         //添加项目  
  117.         private function addItem():void  
  118.         {  
  119.             reflectionClip.addChild( reflectionBMP );  
  120.             reflectionClip.addChild( reflectionMask );  
  121.             reflectionContainer.addChild( reflectionClip );               
  122.         }  
  123.           
  124.           
  125.         //清除倒影  
  126.         public function clearAll():void  
  127.         {  
  128.             reflectionClip.removeChild( reflectionMask );  
  129.             reflectionClip.removeChild( reflectionBMP );  
  130.             reflectionContainer.removeChild( reflectionClip );  
  131.         }  
  132.     }  
  133. }  
package org.summerTree.effect{ //倒影类 import flash.display.*; import flash.geom.*; public class Reflection   {  private var reflectionContainer:DisplayObjectContainer;  private var reflectionHeight:Number;  private var reflectionalphaStrength:Number;//透明度  private var reflectionPercent:Number;  private var offDistance:Number;//偏移距离  private var reflectionClip:Sprite;    private var reflectionBMP:Bitmap;//倒影位图  private var reflectionMask:Sprite;//倒影遮罩  private var RegPointType:String;//注册点位置类型    //实现三种情况进行倒影  public static var LEFT_TOP:String="left_top";  public static var CENTER:String="center";  public static var CENTER_BOTTOM:String="center_bottom";          /* @ para reflectionContainer 倒影的容器   * @ para reflectionHeight  倒影高度   * @ para RegPointType  注册点类型,根据不同注册点位置做出相应的倒影   * @ para alphaStrength 透明度 (0-1)   * @ para reflectionPercent 倒影映射的百分比   * @ para offDistance 偏移距离   */         public function Reflection(reflectionContainer:DisplayObjectContainer, reflectionHeight:Number = 255, RegPointType:String="left_top" ,alphaStrength:Number = 1, reflectionPercent:Number = -1 ,offDistance:Number=0)  {   this.reflectionContainer = reflectionContainer;   this.reflectionHeight = reflectionHeight;   this.reflectionalphaStrength = alphaStrength;   this.reflectionPercent = reflectionPercent;   this.RegPointType=RegPointType;   this.offDistance=offDistance;   CreatReflection();   addItem();  }            //创建倒影  private function CreatReflection():void  {   reflectionClip = new Sprite();//倒影剪辑容器   reflectionMask = new Sprite();//遮罩      var bmd:BitmapData = new BitmapData(reflectionContainer.width,reflectionContainer.height,true,0xffffff);   if(RegPointType==Reflection.LEFT_TOP)   {    bmd.draw(reflectionContainer);    reflectionBMP = new Bitmap(bmd);       reflectionBMP.scaleY= -1;       reflectionBMP.x = 0;       reflectionBMP.y = reflectionBMP.height*2+offDistance;    reflectionMask.y = reflectionBMP.height+offDistance;       reflectionMask.x = 0;   }   else if(RegPointType==Reflection.CENTER)   {    var matrix:Matrix=new Matrix();       matrix.tx=reflectionContainer.width/2;       matrix.ty=reflectionContainer.height/2;       bmd.draw( reflectionContainer,matrix);    reflectionBMP = new Bitmap(bmd);       reflectionBMP.scaleY= -1;       reflectionBMP.x = -reflectionBMP.width/2;       reflectionBMP.y = reflectionBMP.height+reflectionBMP.height/2+offDistance;    reflectionMask.y = reflectionBMP.height/2+offDistance;       reflectionMask.x = -reflectionBMP.width/2;   }   else if(RegPointType==Reflection.CENTER_BOTTOM)   {    var matrixB:Matrix=new Matrix();       matrixB.tx=reflectionContainer.width/2;       matrixB.ty=reflectionContainer.height;          bmd.draw( reflectionContainer,matrixB);    reflectionBMP = new Bitmap(bmd);       reflectionBMP.scaleY= -1;       reflectionBMP.x = -reflectionBMP.width/2;       reflectionBMP.y = reflectionBMP.height+offDistance;    reflectionMask.y = 0+offDistance;       reflectionMask.x = -reflectionBMP.width/2;   }       var fillType:String = GradientType.LINEAR;   var colors:Array = [0xFFFFFF,0xFFFFFF];   var alphas:Array = [reflectionalphaStrength,0];   var ratios:Array = [0,reflectionHeight];   var matr:Matrix = new Matrix();   var matrixHeight:Number;   if(reflectionPercent<=0)   {    matrixHeight=reflectionContainer.height;   }   else   {    matrixHeight=reflectionContainer.height*reflectionPercent;   }   var spreadMethod:String = SpreadMethod.PAD;   matr.createGradientBox(reflectionContainer.width ,matrixHeight, 0.5*Math.PI,0, 0);   reflectionMask.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);   reflectionMask.graphics.drawRect(0, 0, reflectionContainer.width, reflectionContainer.height);            reflectionMask.graphics.endFill();                    reflectionBMP.cacheAsBitmap = true;         reflectionMask.cacheAsBitmap = true;      reflectionBMP.mask = reflectionMask;  }  //添加项目  private function addItem():void  {   reflectionClip.addChild( reflectionBMP );   reflectionClip.addChild( reflectionMask );   reflectionContainer.addChild( reflectionClip );      }            //清除倒影  public function clearAll():void  {   reflectionClip.removeChild( reflectionMask );   reflectionClip.removeChild( reflectionBMP );   reflectionContainer.removeChild( reflectionClip );  } }}

 

           

给我老师的人工智能教程打call!http://blog.****.net/jiangjunshow

flash特效原理 CoverFlow 效果 2