写了一个Flash的Transition

阅读更多

写了一个Flash的Transition

 package
{
import flash.display.*;
import flash.geom.*;
import fl.transitions.*;
import fl.transitions.easing.*;
import fl.motion.BezierSegment;
 
 
public class MarsFly extends Transition
{
 private var _origin_x:Number;
 private var _origin_y:Number;
 private var _origin_zoom:Number;
 private var _origin_alpha:Number;
 private var _start_x:Number = 0;
 private var _start_y:Number = 0;
 private var _control_x:Number = 0;
 private var _control_y:Number = 0;
 private var _start_zoom:Number = 2.5;
 private var _start_alpha:Number = 0;
 private var _bezier:BezierSegment;
 
    /**
     * @private
     */
 override public function get type():Class
 {
  return MarsFly;
 }
 
 
 
    /**
     * @private
  * @param transParams - 参数zoom,alpha,x 起始点x,y 起始点y,cx 控制点x,cy 控制点y
     */
 function MarsFly (content:MovieClip, transParams:Object, manager:TransitionManager)
 {
  super(content, transParams, manager);
  _origin_x = this.manager.contentAppearance.x;
  _origin_y = this.manager.contentAppearance.y;
  _origin_zoom = this.manager.contentAppearance.scaleX;
  _origin_alpha = this.manager.contentAppearance.alpha;
  _start_x = (transParams.x)?transParams.x:0;
  _start_y = (transParams.y)?transParams.y:0;
  _start_zoom = (transParams.zoom)?transParams.zoom:2.5;
  _start_alpha = (transParams.alpha)?transParams.alpha:0;
  _control_x = transParams.cx;
  _control_y = transParams.cy;
 
  _bezier = new BezierSegment(new Point(_start_x, _start_y),
         new Point(_start_x, _start_y),
         new Point(_control_x, _control_y),
         new Point(_origin_x, _origin_y)
         );
 }
 
    /**
     * @private
     */    
 override protected function _render(p:Number):void
 {
  var point:Point = this._bezier.getValue(p);
  this._content.x = point.x;//this._start_x + (this._origin_x - this._start_x) * (Math.sin(p*Math.PI/2));
  this._content.y = point.y;//this._start_y + (this._origin_y - this._start_y) * (Math.cos((1-p)*Math.PI/2));
  this._content.alpha = this._start_alpha + (this._origin_alpha - this._start_alpha) *p;
  this._content.scaleX = this._content.scaleY = this._start_zoom + (this._origin_zoom - this._start_zoom) *p;
 }
 
}
 
 
 
}

调用时

import fl.transitions.*;
import fl.transitions.easing.*;
 
btn1.addEventListener(MouseEvent.CLICK, function (event){
TransitionManager.start(img1_mc, {type:MarsFly, direction:Transition.OUT, duration:2, easing:Strong.easeOut, x:300,y:300, cx:300, cy: 0,zoom:5,alpha:0.1});               
              });
 
btn2.addEventListener(MouseEvent.CLICK, function (event){
TransitionManager.start(img1_mc, {type:MarsFly, direction:Transition.IN, duration:2, easing:Strong.easeOut,x:300,y:300, cx:300, cy: 0,zoom:0.1,alpha:0});                           });

 

你可能感兴趣的:(Flash)