• TweenLite使用一例


    TweenLite的效果:

    fla代码:
    1 var a:runPic=new runPic("http://images.cnblogs.com/cnblogs_com/ddw1997/img/yaoming.jpg");
    2 addChild(a);
    3 a.addEventListener(runPic.LOADER_EVENT,set_xy);
    4 function set_xy(e:Event ):void {
    5     a.x=(stage.stageWidth-a.width)/2;
    6     a.y=(stage.stageHeight-a.height)/2;
    7     a.removeEventListener(runPic.LOADER_EVENT,set_xy);
    8 }

    runPic.as
     1 /*===========================================================
     2 * 构造函数有五个参数,第一个是图片地址是必需的。
     3 * var a:runPic=new runPic("yaoming.jpg");
     4 * addChild(a);
     5 * a.addEventListener(runPic.LOADER_EVENT,set_xy);
     6 * function set_xy(e:Event ):void {
     7 * a.x=(stage.stageWidth-a.width)/2;
     8 * a.y=(stage.stageHeight-a.height)/2;
     9 * a.removeEventListener(runPic.LOADER_EVENT,set_xy);
    10 * }
    11 *=================作者;ddw1997(20090703)======================*/
    12 package {
    13     //Import TweenLite
    14     import gs.*;
    15     import gs.easing.*;
    16     import flash.display.Bitmap;
    17     import flash.display.BitmapData;
    18     import flash.display.Sprite;
    19     import flash.display.MovieClip;
    20     import flash.display.Loader;
    21     import flash.net.URLRequest;
    22     import flash.events.Event;
    23     import flash.events.MouseEvent;
    24     import flash.geom.Rectangle;
    25     import flash.geom.Point;
    26     public class runPic extends Sprite {
    27         private var X_num:int;//宽等分数
    28         private var Y_num:int;//高等分数
    29         private var X_Number;//小块的宽
    30         private var Y_height:Number;//小块的高
    31         private var line_Color:uint;//小块边线颜色
    32         private var line_Width:uint;//小块边线宽度
    33         private var image_Num:int;//统计分成小块的数量
    34         private var image_URL:String;//图片地址
    35         private var imageLoader:Loader;
    36         public static var LOADER_EVENT = "loaderevent";
    37         public function runPic(image_url:String,x_num:int=10,y_num:int=10,line_color:uint=0xffffffff,line_int=1):void {
    38             X_num = x_num;
    39             Y_num = y_num;
    40             line_Color = line_color;
    41             line_Width = line_width;
    42             image_URL = image_url;
    43             init();
    44         }
    45         private function init():void {
    46             imageLoader = new Loader();
    47             imageLoader.load(new URLRequest(image_URL));
    48             imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
    49         }
    50         private function completeHandler(event:Event):void {
    51             var image_Data:BitmapData = event.target.content.bitmapData;
    52             X_width = Math.floor(image_Data.width / X_num);//取整便于获得像素的整数值,使得边框的像素太小时不至于被遮盖。
    53             Y_height = Math.floor(image_Data.height / Y_num);
    54             image_Num = 0;
    55             for (var i = 0; i < X_num; i++) {
    56                 for (var j = 0; j < Y_num; j++) {
    57                     var image_MC:MovieClip = new MovieClip();//MovieClip便于响应鼠标事件及动态添加属性。
    58                     var image_bitmap:Bitmap = new Bitmap();
    59                     image_bitmap.bitmapData = new BitmapData(X_width + 2 * line_Width,Y_height + 2 * line_Width,true,line_Color);
    60                     image_bitmap.bitmapData.copyPixels(image_Data,new Rectangle(i * X_width, j * Y_height, X_width, Y_height),new Point(line_Width,line_Width));
    61                     image_MC.addChild(image_bitmap);
    62                     image_MC.x = i * (X_width+line_Width);
    63                     image_MC.y = j * (Y_height+line_Width);
    64                     image_MC.oldX = image_MC.x;
    65                     image_MC.oldY = image_MC.y;
    66                     image_MC.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
    67                     addChild(image_MC);
    68                     if (image_Num == X_num * Y_num - 1) {
    69                         dispatchEvent(new Event(LOADER_EVENT));//发布广播小块全部完成
    70                     }
    71                     image_Num++;
    72                 }
    73             }
    74         }
    75         private function mouseOverHandler(e:Event):void {
    76             var image_MC:MovieClip = e.target as MovieClip;
    77             var randomX:Number = Math.random() * 1000 - 500;
    78             var randomY:Number = Math.random() * 1000 - 500;
    79             var targetX:Number = image_MC.x + randomX;
    80             var targetY:Number = image_MC.y + randomY;
    81             TweenLite.to(image_MC, 1, {x:targetX, y:targetY, onComplete:outTweenFinished, onCompleteParams:[image_MC]});
    82             setChildIndex(image_MC,image_Num - 1);//让小块到最上层
    83             image_MC.removeEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);//让小块删除侦听
    84         }
    85         private function outTweenFinished(image_MC:MovieClip):void {
    86             var oldX = image_MC.oldX;
    87             var oldY = image_MC.oldY;
    88             TweenLite.to(image_MC, 1, {x:oldX, y:oldY, onComplete:inTweenFinished, onCompleteParams:[image_MC]});
    89         }
    90         private function inTweenFinished(image_MC:MovieClip):void {
    91             image_MC.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);//让小块重新侦听
    92         }
    93 
    94     }
    95 }
  • 相关阅读:
    tushare包使用案例
    Matplotlib模块:绘图和可视化
    pandas使用
    django 表操作
    元数据Meta
    django关系类型字段
    django项目模型字段
    django项目mysite 2
    django安装使用xadmin
    GCC版本中没有GLIBCXX_3.4.15错误
  • 原文地址:https://www.cnblogs.com/ddw1997/p/1542281.html
Copyright © 2020-2023  润新知