[ActionScript 3.0] AS3 用于拖动对象时跟随鼠标的缓动效果
package com.fylibs.components.effects
{
import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.MouseEvent; /**
* 用于拖动对象时的缓动效果
* @author Frost.Yen
* @E-mail 871979853@qq.com
* @create 2015-12-11 下午3:22:27
*
*/
public class DragMove
{
private var _direction:String = "horizontal";
private var _ratio:Number = 0.900000;
/**
* 按下的坐标(当horizontal时为x坐标,当vertical时为y坐标)
*/
private var _downCoor:Number;
/**
* 移动的坐标(当horizontal时为x坐标,当vertical时为y坐标)
*/
private var _moveCoor:Number;
/**
* 缓动偏移量
*/
private var _offset:Number;
/**
* 坐标标记(当horizontal时为x,当vertical时为y)
*/
private var _coor:String = "mouseX";
/**
* 标记是否按下状态
*/
private var _isDown:Boolean;
private var _target:DisplayObject;
private var _max:Number;
private var _min:Number;
/**
* 拖拽缓动
* @param target 需要拖拽的对象
* @param max 拖拽对象的最大坐标值
* @param min 拖拽对象的最小坐标值
* @param direction 缓动方向
*/
public function DragMove(target:DisplayObject,max:Number,min:Number,direction:String="horizontal")
{
_max = max;
_min = min;
_direction = direction;
_direction == "horizontal"?_coor = "mouseX":_coor = "mouseY";
_target = target;
_target.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
}
/**
* 刷新
* @param max 拖拽对象的最大坐标值
* @param min 拖拽对象的最小坐标值
*/
public function refresh(max:Number,min:Number):void
{
_max = max;
_min = min;
}
private function onDown(e:MouseEvent):void
{
_isDown = true;
_downCoor = _target[_coor];
_target.stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
_target.stage.addEventListener(MouseEvent.MOUSE_UP, onUp);
_target.addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
private function onEnterFrame(e:Event):void
{
_offset = _offset * _ratio;
_target.x = _target.x + _offset;
if (_target.x < _min){
_target.x = _min ;
}
if (_target.x > _max){
_target.x = _max;
}
if(Math.abs(_offset)<0.001){
_offset+=0.1;
_target.removeEventListener(Event.ENTER_FRAME,onEnterFrame);
}
}
private function onMove(e:MouseEvent):void
{
if (_isDown) {
_moveCoor = _target[_coor];
_offset = _moveCoor - _downCoor
_offset = _offset / 20;
}
}
private function onUp(e:MouseEvent):void
{
_isDown = false;
_target.stage.removeEventListener(MouseEvent.MOUSE_UP, onUp);
_target.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMove); }
/**
* 移动方向,horizontal横向,vertical纵向
*/
public function get direction():String
{
return _direction;
} /**
* @private
*/
public function set direction(value:String):void
{
_direction = value;
} /**
* 缓动系数
*/
public function get ratio():Number
{
return _ratio;
} /**
* @private
*/
public function set ratio(value:Number):void
{
_ratio = value;
} }
}
[ActionScript 3.0] AS3 用于拖动对象时跟随鼠标的缓动效果的更多相关文章
- [ActionScript 3.0] AS3 用于拖动对象时一次一页的缓动
package com.fylibs.components.effects{ import com.tweener.transitions.Tweener; import flash.display. ...
- WPF中ListBox滚动时的缓动效果
原文:WPF中ListBox滚动时的缓动效果 上周工作中遇到的问题: 常规的ListBox在滚动时总是一格格的移动,感觉上很生硬. 所以想要实现类似Flash中的那种缓动的效果,使ListBox滚动时 ...
- [ActionScript 3.0] as3处理xml的功能和遍历节点
as3比as2处理xml的功能增强了N倍,获取或遍历节点非常之方便,类似于json对像的处理方式. XML 的一个强大功能是它能够通过文本字符的线性字符串提供复杂的嵌套数据.将数据加载到 XML 对象 ...
- [ActionScript 3.0] AS3.0 动态加载显示内容
可以将下列任何外部显示资源加载到 ActionScript 3.0 应用程序中: 在 ActionScript 3.0 中创作的 SWF 文件 — 此文件可以是 Sprite.MovieClip 或扩 ...
- [ActionScript 3.0] AS3 深入理解Flash的安全沙箱Security Domains
简介 如果你还没有与复杂的的安全域(security domain)和应用程序域(application domain)问题打过交道,那么你真是个幸运的家伙.当你在加载外部内容(然后他们开始播放)的时 ...
- [ActionScript 3.0] AS3.0 对象在一定范围随机显示不重叠
import flash.geom.Rectangle; import flash.display.MovieClip; import flash.display.Sprite; var arr:Ar ...
- [ActionScript 3.0] AS3.0 对象在矩形范围随机运动
package com.views { import flash.display.Bitmap; import flash.display.MovieClip; import flash.displa ...
- [ActionScript 3.0] AS3.0 Loader加载子swf时是否需要指定新的应用程序域ApplicationDomain
实际应用中, Loader加载子swf时是否需要指定新的应用程序域ApplicationDomain,需要择情况而定. 1.如果在本地将项目位置添加到flashplayer受信任位置(上一篇文章所述) ...
- [ActionScript 3.0] as3.0加载as2.0的swf时获取as2.0的实际舞台尺寸
var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.INIT, initHandler) ...
随机推荐
- URI、URL和URN
URI.URL和URN URI :Uniform Resource Identifier,通用资源标识符: URL:Uniform Resource Locator,统一资源定位符: URN:Unif ...
- linux服务之openfiler
架构:b/s 服务器端:封装好的linux系统 客户端:浏览器 相关包:封装好的linux系统 Openfiler imports user and group information from ce ...
- unity, Graphics.Blit (null, null, mat,0);
我使用 Graphics.Blit (null, finalRT, mat); 合成出一张finalRT,然后将finalRT用在editor脚本的OnInspector中使用 Graphics.Dr ...
- Ackerman函数
Ackerman函数在许多讲解递归的书中都提到,但似乎又对解题没有太大的意义,暂时不知道了.不过这个东西,是一个数学知识点,暂时收藏于此吧. 查了一下维基百科和百度百科,表面上两个定义不一样,仔细推敲 ...
- ie8下table的colspan属性与max-with属性的显示错乱问题
今天项目测试时发现了一个table的colspan样式问题,发现colspan单元格下的的元素设置max-with后将上面的第二列单元格撑开了,导致后面单元格的内容换行,先看代码: html代码: & ...
- [转][工地][存]Oracle触发器死锁问题解决
摘自http://blog.itpub.net/12932950/viewspace-607691/ 这两天一直在因为系统初期设计原因导致的一个触发器问题.问题如下:有表T,有客户编号.账户编号及地址 ...
- WCF 遇到 由于线程退出或应用程序请求,已放弃 I/O 操作 ListenerContextInputStream
异常类型:IOException 异常消息:An exception has been thrown when reading the stream. 异常信息: at System.ServiceM ...
- TX Textcontrol 使用总结一
以下内容纯属个人使用感想,如有问题,还望讲解!!! 简介与使用感想: TX Text Control是一套功能丰富的文字处理控件,它以可重复使用控件的形式为开发人员提供了Word中常用的文字处理功能, ...
- 利用NTFS权限与虚拟目录,在IIS 6.0的默认FTP站点中做用户隔离。
默认FTP站点为不隔离用户站点,利用NTFS权限设置,达到仅能访问指定目录效果. 是否允许匿名连接 FTP站点主目录:站点范围内有没有用户需要上传,有的话,要勾选“写入”:具体用户使用NTFS还给予写 ...
- item31,连续子数组的最大和
整型数组,元素有正数和负数.数组中一个或连续的多个整数组成一个子数组,求所有子数组中最大值. =========== 动态规划, 状态转移方程,max[].size = nums.size() max ...