1. package com.fylibs.components.effects
  2. {
  3. import flash.display.DisplayObject;
  4. import flash.events.Event;
  5. import flash.events.MouseEvent;
  6.  
  7. /**
  8. * 用于拖动对象时的缓动效果
  9. * @author Frost.Yen
  10. * @E-mail 871979853@qq.com
  11. * @create 2015-12-11 下午3:22:27
  12. *
  13. */
  14. public class DragMove
  15. {
  16. private var _direction:String = "horizontal";
  17. private var _ratio:Number = 0.900000;
  18. /**
  19. * 按下的坐标(当horizontal时为x坐标,当vertical时为y坐标)
  20. */
  21. private var _downCoor:Number;
  22. /**
  23. * 移动的坐标(当horizontal时为x坐标,当vertical时为y坐标)
  24. */
  25. private var _moveCoor:Number;
  26. /**
  27. * 缓动偏移量
  28. */
  29. private var _offset:Number;
  30. /**
  31. * 坐标标记(当horizontal时为x,当vertical时为y)
  32. */
  33. private var _coor:String = "mouseX";
  34. /**
  35. * 标记是否按下状态
  36. */
  37. private var _isDown:Boolean;
  38. private var _target:DisplayObject;
  39. private var _max:Number;
  40. private var _min:Number;
  41. /**
  42. * 拖拽缓动
  43. * @param target 需要拖拽的对象
  44. * @param max 拖拽对象的最大坐标值
  45. * @param min 拖拽对象的最小坐标值
  46. * @param direction 缓动方向
  47. */
  48. public function DragMove(target:DisplayObject,max:Number,min:Number,direction:String="horizontal")
  49. {
  50. _max = max;
  51. _min = min;
  52. _direction = direction;
  53. _direction == "horizontal"?_coor = "mouseX":_coor = "mouseY";
  54. _target = target;
  55. _target.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
  56. }
  57. /**
  58. * 刷新
  59. * @param max 拖拽对象的最大坐标值
  60. * @param min 拖拽对象的最小坐标值
  61. */
  62. public function refresh(max:Number,min:Number):void
  63. {
  64. _max = max;
  65. _min = min;
  66. }
  67. private function onDown(e:MouseEvent):void
  68. {
  69. _isDown = true;
  70. _downCoor = _target[_coor];
  71. _target.stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
  72. _target.stage.addEventListener(MouseEvent.MOUSE_UP, onUp);
  73. _target.addEventListener(Event.ENTER_FRAME,onEnterFrame);
  74. }
  75. private function onEnterFrame(e:Event):void
  76. {
  77. _offset = _offset * _ratio;
  78. _target.x = _target.x + _offset;
  79. if (_target.x < _min){
  80. _target.x = _min ;
  81. }
  82. if (_target.x > _max){
  83. _target.x = _max;
  84. }
  85. if(Math.abs(_offset)<0.001){
  86. _offset+=0.1;
  87. _target.removeEventListener(Event.ENTER_FRAME,onEnterFrame);
  88. }
  89. }
  90. private function onMove(e:MouseEvent):void
  91. {
  92. if (_isDown) {
  93. _moveCoor = _target[_coor];
  94. _offset = _moveCoor - _downCoor
  95. _offset = _offset / 20;
  96. }
  97. }
  98. private function onUp(e:MouseEvent):void
  99. {
  100. _isDown = false;
  101. _target.stage.removeEventListener(MouseEvent.MOUSE_UP, onUp);
  102. _target.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMove);
  103.  
  104. }
  105. /**
  106. * 移动方向,horizontal横向,vertical纵向
  107. */
  108. public function get direction():String
  109. {
  110. return _direction;
  111. }
  112.  
  113. /**
  114. * @private
  115. */
  116. public function set direction(value:String):void
  117. {
  118. _direction = value;
  119. }
  120.  
  121. /**
  122. * 缓动系数
  123. */
  124. public function get ratio():Number
  125. {
  126. return _ratio;
  127. }
  128.  
  129. /**
  130. * @private
  131. */
  132. public function set ratio(value:Number):void
  133. {
  134. _ratio = value;
  135. }
  136.  
  137. }
  138. }

[ActionScript 3.0] AS3 用于拖动对象时跟随鼠标的缓动效果的更多相关文章

  1. [ActionScript 3.0] AS3 用于拖动对象时一次一页的缓动

    package com.fylibs.components.effects{ import com.tweener.transitions.Tweener; import flash.display. ...

  2. WPF中ListBox滚动时的缓动效果

    原文:WPF中ListBox滚动时的缓动效果 上周工作中遇到的问题: 常规的ListBox在滚动时总是一格格的移动,感觉上很生硬. 所以想要实现类似Flash中的那种缓动的效果,使ListBox滚动时 ...

  3. [ActionScript 3.0] as3处理xml的功能和遍历节点

    as3比as2处理xml的功能增强了N倍,获取或遍历节点非常之方便,类似于json对像的处理方式. XML 的一个强大功能是它能够通过文本字符的线性字符串提供复杂的嵌套数据.将数据加载到 XML 对象 ...

  4. [ActionScript 3.0] AS3.0 动态加载显示内容

    可以将下列任何外部显示资源加载到 ActionScript 3.0 应用程序中: 在 ActionScript 3.0 中创作的 SWF 文件 — 此文件可以是 Sprite.MovieClip 或扩 ...

  5. [ActionScript 3.0] AS3 深入理解Flash的安全沙箱Security Domains

    简介 如果你还没有与复杂的的安全域(security domain)和应用程序域(application domain)问题打过交道,那么你真是个幸运的家伙.当你在加载外部内容(然后他们开始播放)的时 ...

  6. [ActionScript 3.0] AS3.0 对象在一定范围随机显示不重叠

    import flash.geom.Rectangle; import flash.display.MovieClip; import flash.display.Sprite; var arr:Ar ...

  7. [ActionScript 3.0] AS3.0 对象在矩形范围随机运动

    package com.views { import flash.display.Bitmap; import flash.display.MovieClip; import flash.displa ...

  8. [ActionScript 3.0] AS3.0 Loader加载子swf时是否需要指定新的应用程序域ApplicationDomain

    实际应用中, Loader加载子swf时是否需要指定新的应用程序域ApplicationDomain,需要择情况而定. 1.如果在本地将项目位置添加到flashplayer受信任位置(上一篇文章所述) ...

  9. [ActionScript 3.0] as3.0加载as2.0的swf时获取as2.0的实际舞台尺寸

    var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.INIT, initHandler) ...

随机推荐

  1. 关于spring 3.0.5的 <mvc:resources mapping="***" location="***">标签的使用

    spring mvc 的<mvc;resources mapping="***" location="***">标签是在spring3.0.4出现的 ...

  2. Oracle数据库—— 存储过程与函数的创建

    一.涉及内容 1.掌握存储过程与函数的概念. 2.能够熟练创建和调用存储过程与函数. 二.具体操作 1.创建存储过程,根据职工编号删除scott.emp表中的相关记录. (1)以scott 用户连接数 ...

  3. 网络工程实训_2路由器基本配置及IOS介绍

    实验2:路由器基本配置及IOS介绍.包括:CLI的使用与IOS基本命令:配置文件的备份和IOS的备份:CDP协议. 一.实验目的 1.熟悉路由器CLI的各种模式: 2.熟悉路由器CLI的各种编辑命令: ...

  4. document cookie用法

    cookie概述 曾经利用一个不变的框架来存储购物栏数据,而商品显示页面是不断变化的,尽管这样能达到一个模拟 全局变量的功能,但并不严谨.例如在导航框架页面内右击,单击快捷菜单中的[刷新]命令,则所有 ...

  5. android 如何让文本中某个关键字高亮显示?

    TextView tv = (TextView) findViewById(R.id.hello);SpannableString s = new SpannableString(getResourc ...

  6. Oracle查找表的外键引用关系

    Oracle查找表的外键引用关系 select t1.table_name, t2.table_name as "TABLE_NAME(R)", t1.constraint_nam ...

  7. [JAVA] java程序性能优化

    一.避免在循环条件中使用复杂表达式 在不做编译优化的情况下,在循环中,循环条件会被反复计算,如果不使用复杂表达式,而使循环条件值不变的话,程序将会运行的更快. 例子: import java.util ...

  8. iText导出pdf、word、图片

    一.前言 在企业的信息系统中,报表处理一直占比较重要的作用,本文将介绍一种生成PDF报表的Java组件--iText.通过在服务器端使用Jsp或JavaBean生成PDF报表,客户端采用超级连接显示或 ...

  9. 【jmeter】关联-正则表达和xpath

    话说LoadRunner有的一些功能,比如:参数化.检查点.集合点.关联,Jmeter也都有这些功能,只是功能可能稍弱一些,今天就关联来讲解一下. JMeter的关联方法有两种:后置处理器-正则表达式 ...

  10. jquery 整理之一

    1.选择器: jQuery 属性选择器 jQuery 使用 XPath 表达式来选择带有给定属性的元素. $("[href]") 选取所有带有 href 属性的元素. $(&quo ...