Chinaunix首页 | 论坛 | 博客
  • 博客访问: 474587
  • 博文数量: 280
  • 博客积分: 337
  • 博客等级: 二等列兵
  • 技术积分: 1957
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-17 21:36
文章分类

全部博文(280)

文章存档

2017年(13)

2016年(38)

2015年(78)

2014年(67)

2013年(70)

2012年(14)

分类: C/C++

2013-07-04 10:33:03

fla例子: 

点击(此处)折叠或打开

  1. /**
  2.  * ...
  3.  * @author ...
  4.  */

  5. class CFSSlidableVector extends MovieClip
  6. {
  7.     var mChildArray:Array;
  8.     var mChildNum:Number = 0;
  9.     var mLastChildPosY:Number = 0;
  10.     var mChildIntervalPercent:Number = 0.5;
  11.     var mChildLastPosYmouse:Number = 0;
  12.     var mChildFrameNum:Number = 0;
  13.     var mFlySpeedY:Number = 0;
  14.     var mFlyFrames:Number = 0;
  15.     var mFlyDistance:Number = 0;
  16.     var mIsFlying:Boolean = false;
  17.     var mHeight:Number = 0;
  18.     var mChildSlideDistance:Number = 0;
  19.     var mChildListHeight:Number = 0;
  20.     var mChildListStartPosY:Number = 0;
  21.     var mChildListEndPosY:Number = 0;
  22.     var mChildFlyTargetY:Number = 0;
  23.     var mOnPressFunc = null;
  24.     var mOnReleaseFunc = null;
  25.     var mOnReleaseOutsideFunc = null;
  26.     var mOnPressMoved:Boolean = true;
  27.     var mChildStartPosY:Number = 0;
  28.     var mIsValidPress:Boolean = false;
  29.     
  30.     public function CFSSlidableVector()
  31.     {
  32.         this.mChildArray = new Array();
  33.         this.mHeight = this._height;
  34.     }
  35.     
  36.     public function addOneChild(childName)
  37.     {
  38.         
  39.         this.mChildNum = this.mChildNum + 1;
  40.         var child = this.attachMovie(childName, ("" + this + "_" + childName + "_" + this.mChildNum), this.getNextHighestDepth());
  41.         this.mChildArray.push(child);
  42.         child._x = (this._width - child._width) / 2;
  43.         if (this.mLastChildPosY == 0)
  44.         {
  45.             child._y = this.mChildIntervalPercent * child._height;
  46.             child.mChildStartPosY = child._y;
  47.             this.mLastChildPosY = child._y;
  48.             this.mChildListStartPosY = child._y;
  49.             this.mChildListHeight = child._height;
  50.         }
  51.         else
  52.         {
  53.             child._y = this.mLastChildPosY + (1 + this.mChildIntervalPercent) * child._height;
  54.             child.mChildStartPosY = child._y;
  55.             this.mLastChildPosY = child._y;
  56.             this.mChildListHeight = this.mChildListHeight + child._height * (this.mChildIntervalPercent + 1);
  57.         }
  58.     }
  59.     
  60.     
  61.     public function mcFly(distanceY, frames)
  62.     {
  63.         if( (distanceY == 0) || (frames == 0) )
  64.         {
  65.             return;
  66.         }
  67.         
  68.         this.mFlyDistance = distanceY;
  69.         this.mFlyFrames = frames;
  70.         this.mFlySpeedY = distanceY / frames;
  71.         this.mIsFlying = true;
  72.         this.mChildFlyTargetY = this._y + this.mFlyDistance;
  73.         
  74.         this.onEnterFrame = function()
  75.         {
  76.             this.mFlyFrames = this.mFlyFrames - 1;
  77.             this._y = this._y + this.mFlySpeedY;
  78.             if (mFlyFrames <= 0)
  79.             {
  80.                 this._y = this.mChildFlyTargetY;
  81.                 this.mChildFlyTargetY = 0;
  82.                 this.mIsFlying = false;
  83.                 this.onEnterFrame = null;
  84.             }
  85.         }
  86.     }
  87.     
  88.     public function childSlide(distanceY, firstFrames, interval)
  89.     {
  90.         if (this.isAnyChildFlying() == true)
  91.         {
  92.             return;
  93.         }

  94.         if(distanceY == 0)
  95.         {
  96.             return;
  97.         }
  98.         this.mChildSlideDistance = this.mChildSlideDistance + distanceY;
  99.         if (distanceY < 0)
  100.         {
  101.             for (var i = 0; i < this.mChildArray.length; i++)
  102.             {
  103.                 this.mChildArray[i].mcFly(distanceY, firstFrames + i * interval);
  104.             }
  105.         }
  106.         else
  107.         {
  108.             for (var i = this.mChildArray.length - 1; i >= 0; i--)
  109.             {
  110.                 this.mChildArray[i].mcFly(distanceY, firstFrames + (this.mChildArray.length - 1 - i) * interval);
  111.             }
  112.         }
  113.         this.mLastChildPosY = this.mLastChildPosY + distanceY;
  114.     }
  115.     
  116.     public function childSlideNoCaculateSlideDistance(distanceY, firstFrames, interval)
  117.     {
  118.         if (this.isAnyChildFlying() == true)
  119.         {
  120.             return;
  121.         }

  122.         if(distanceY == 0)
  123.         {
  124.             return;
  125.         }
  126.         if (distanceY < 0)
  127.         {
  128.             for (var i = 0; i < this.mChildArray.length; i++)
  129.             {
  130.                 this.mChildArray[i].mcFly(distanceY, firstFrames + i * interval);
  131.             }
  132.         }
  133.         else
  134.         {
  135.             for (var i = this.mChildArray.length - 1; i >= 0; i--)
  136.             {
  137.                 this.mChildArray[i].mcFly(distanceY, firstFrames + i * interval);
  138.             }
  139.         }
  140.         
  141.         this.mLastChildPosY = this.mLastChildPosY + distanceY;
  142.     }
  143.     
  144.     public function allSlide(distanceY, parent_frames, interval)
  145.     {
  146.         var pre_height = this._height;
  147.         this.mcFly(distanceY, parent_frames);
  148.         this.childMoveNoCaculateSlideDistance(pre_height);
  149.         this.childSlideNoCaculateSlideDistance(-pre_height, parent_frames + interval, interval);
  150.     }
  151.     
  152.     public function isAnyChildFlying()
  153.     {
  154.         for (var i = 0; i < this.mChildArray.length; i++)
  155.         {
  156.             if (this.mChildArray[i].mIsFlying == true)
  157.             {
  158.                 return true;
  159.             }
  160.         }
  161.         
  162.         return false;
  163.     }
  164.     
  165.     public function childMoveNoCaculateSlideDistance(distance)
  166.     {
  167.         for (var i = 0; i < this.mChildArray.length; i++)
  168.         {
  169.             var c = this.mChildArray[i];
  170.             c._y = c._y + distance;
  171.         }
  172.     }
  173.     
  174.     public function childMove(distance)
  175.     {
  176.         this.mChildSlideDistance = this.mChildSlideDistance + distance;
  177.         for (var i = 0; i < this.mChildArray.length; i++)
  178.         {
  179.             var c = this.mChildArray[i];
  180.             c._y = c._y + distance;
  181.         }
  182.     }
  183.     
  184.     public function fixChildPosY()
  185.     {
  186.         if ((this.mChildListHeight + this.mChildSlideDistance) <= 0)
  187.         {
  188.             this.childMove(this.mChildListStartPosY - (this.mChildListHeight + this.mChildSlideDistance));
  189.         }
  190.         if ((this.mChildListStartPosY + this.mChildSlideDistance) >= (this.mHeight - this.mChildListStartPosY))
  191.         {
  192.             this.childMove(this.mHeight - (this.mChildListStartPosY * 3 + this.mChildSlideDistance) );
  193.         }
  194.     }
  195.     
  196.     public function registerTouchEvent(name, func)
  197.     {
  198.         if (name == "onPress")
  199.         {
  200.             this.mOnPressFunc = func;
  201.         }
  202.         else if(name == "onRelease")
  203.         {
  204.             this.mOnReleaseFunc = func;
  205.         }
  206.         else if(name == "onReleaseOutside")
  207.         {
  208.             this.mOnReleaseOutsideFunc = func;
  209.         }
  210.     }
  211.     
  212.     public function setOnPressMoving()
  213.     {
  214.         this.onPress = function()
  215.         {
  216.             this.mIsValidPress = true;
  217.             var d:Number = this.mChildStartPosY + this._ymouse + this._parent.mChildSlideDistance;
  218.             trace("mChildStartPosY: " + this.mChildStartPosY + " _ymouse: " + this._ymouse + " mChildSlideDistance: " + this._parent.mChildSlideDistance);
  219.             if (d < 0 || d > this._parent.mHeight)
  220.             {
  221.                 
  222.                 this.mIsValidPress = false;
  223.                 return;
  224.             }
  225.             
  226.             if (this._parent.isAnyChildFlying() == true)
  227.             {
  228.                 return;
  229.             }

  230.             this.mChildLastPosYmouse = this._ymouse;
  231.             this.mOnPressMoved = false;
  232.             
  233.             this.onEnterFrame = function()
  234.             {
  235.                 if (this.mChildLastPosYmouse != this._ymouse)
  236.                 {
  237.                     this.mOnPressMoved = true;
  238.                 }
  239.                 
  240.                 this._parent.childMove(this._ymouse - this.mChildLastPosYmouse);
  241.                 this._parent.fixChildPosY();
  242.                 
  243.                 this.mChildLastPosYmouse = this._ymouse;
  244.             }
  245.             if (this.mOnPressFunc != null)
  246.             {
  247.                 this.mOnPressFunc();
  248.             }
  249.         }
  250.            
  251.         this.onRelease = function()
  252.         {
  253.             if (this.mIsValidPress != true)
  254.             {
  255.                 return;
  256.             }
  257.             if (this._parent.isAnyChildFlying() == true)
  258.             {
  259.                 return;
  260.             }
  261.             this._parent.fixChildPosY();
  262.             this.onEnterFrame = null;

  263.             if ((this.mOnReleaseFunc != null) && (this.mOnPressMoved == false))
  264.             {
  265.                 this.mOnPressMoved = true;
  266.                 this.mOnReleaseFunc();
  267.             }
  268.         }
  269.             
  270.         this.onReleaseOutside = function()
  271.         {
  272.             if (this.mIsValidPress != true)
  273.             {
  274.                 return;
  275.             }
  276.             if (this._parent.isAnyChildFlying() == true)
  277.             {
  278.                 return;
  279.             }
  280.             this._parent.fixChildPosY();
  281.             this.onEnterFrame = null;
  282.             
  283.     
  284.             var distance = (this._ymouse - this.mChildLastPosYmouse) * 3;
  285.             var frames = distance / this._height / 2;
  286.             if (frames < 0)
  287.             {
  288.                 frames = -frames;
  289.             }
  290.             frames = frames + 1;
  291.             var interval;
  292.             if (frames > 5)
  293.             {
  294.                 interval = 3;
  295.             }
  296.             else
  297.             {
  298.                 interval = 1;
  299.             }
  300.             
  301.             if ((distance + this._parent.mChildListHeight + this._parent.mChildSlideDistance) <= 0)
  302.             {
  303.                 distance = (this._parent.mChildListStartPosY - (this._parent.mChildListHeight + this._parent.mChildSlideDistance));
  304.             }

  305.             if ((distance + this._parent.mChildListStartPosY + this._parent.mChildSlideDistance) >= (this._parent.mHeight - this._parent.mChildListStartPosY))
  306.             {
  307.                 distance = (this._parent.mHeight - (this._parent.mChildListStartPosY * 3 + this._parent.mChildSlideDistance) );
  308.             }
  309.             
  310.             this._parent.childSlide(distance, frames, interval);
  311.             if (this.mOnReleaseOutsideFunc != null)
  312.             {
  313.                 this.mOnReleaseOutsideFunc();
  314.             }
  315.         }
  316.     }
  317.     
  318.     public function setChildOnPressMoving()
  319.     {
  320.         var child;
  321.         for (var i = 0; i < this.mChildArray.length; i++)
  322.         {
  323.             child = this.mChildArray[i];
  324.             child.setOnPressMoving();
  325.         }
  326.     }
  327.     
  328.     /*public function unSetChildOnPressMoving()
  329.     {
  330.         for (var i = 0; i < this.mChildArray.length; i++)
  331.         {
  332.             var child = this.mChildArray[i];
  333.             child.onPress = null;
  334.             child.onRelease = null;
  335.             child.onReleaseOutside = null;
  336.         }
  337.     }*/

  338. }



阅读(944) | 评论(0) | 转发(0) |
0

上一篇:Lua随机数

下一篇:lua当前脚本路径

给主人留下些什么吧!~~