package com.fylibs.components.effects{
import com.tweener.transitions.Tweener; import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.InteractiveObject;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Rectangle; /**
* 用于拖动时一次一页的缓动
* @author Frost.Yen
* @E-mail 871979853@qq.com
* @create 2015-12-11 下午5:06:57
*
*/
public class DragMovePage
{
private var _direction:String = "horizontal";
/**
* 按下的坐标(当horizontal时为x坐标,当vertical时为y坐标)
*/
private var _downCoor:Number;
/**
* 移动的坐标(当horizontal时为x坐标,当vertical时为y坐标)
*/
private var _moveCoor:Number;
/**
* 坐标标记((当horizontal时为mouseX,当vertical时为mouseY))
*/
private var _mouseCoor:String = "mouseX"; /**
* 标记是否按下状态
*/
private var _isDown:Boolean; private var _slidingDis:Number;
private var _slidingNum:Number = 300;
private var _page:uint;
private var _dis:uint;
private var _count:int;
private var _target:Sprite;
private var _dotBar:Sprite;
/**
* 拖拽缓动
* @param target 需要拖拽的对象
* @param page 页数
* @param dis 每页的距离
* @param direction 缓动方向
* @param dotBar 指示当前页的小圆点
*/
public function DragMovePage(target:Sprite,page:uint,dis:uint,direction:String="horizontal",dotBar:Sprite=null)
{
_page = page;
_dis = dis;
_direction = direction;
_dotBar = dotBar;
_direction == "horizontal"?_mouseCoor = "mouseX":_mouseCoor = "mouseY";
_target = target;
_target.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
}
/**
* 拖拽缓动
* @param page 页数
* @param dis 每页的距离
*/
public function refresh(page:uint,dis:uint):void
{
_page = page;
_dis = dis;
}
private function onDown(e:MouseEvent):void
{
Tweener.removeTweens(_target);
_isDown = true;
_downCoor = _target.parent[_mouseCoor];
//注意,-(_page)*_dis中为什么是page,而不是page-1
_direction == "horizontal"?_target.startDrag(false,new Rectangle(-(_page)*_dis,_target.y,(_page+1)*_dis,0)):_target.startDrag(false,new Rectangle(_target.x,-(_page)*_dis,0,(_page+1)*_dis));
_target.stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
_target.stage.addEventListener(MouseEvent.MOUSE_UP, onUp);
}
private function onMove(e:MouseEvent):void
{
_moveCoor = _target.parent[_mouseCoor];
}
private function onUp(e:MouseEvent):void
{
_isDown = false;
_moveCoor = _target.parent[_mouseCoor];
_target.stopDrag();
_target.stage.removeEventListener(MouseEvent.MOUSE_UP, onUp);
_target.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMove);
_slidingDis = _downCoor-_moveCoor;
if(_slidingDis>_slidingNum){
_count++;
}else if(_slidingDis<-_slidingNum){
_count--;
}
if(_count>=_page){
_count = _page-1;
}else if(_count<0){
_count = 0;
}
_direction == "horizontal"?Tweener.addTween(_target,{x:-_count*_dis,time:0.7,transition:"easeOutCubic",onComplete:moveEnd}):Tweener.addTween(_target,{y:-_count*_dis,time:0.7,transition:"easeOutCubic",onComplete:moveEnd});
}
private function moveEnd():void
{
if(_dotBar){
for(var i:int = 0;i<_dotBar.numChildren;i++){
if(_count == i){
_dotBar.getChildAt(i).alpha = 1;
}else{
_dotBar.getChildAt(i).alpha = 0.5;
}
}
}
}
/**
* 移动方向,horizontal横向,vertical纵向
*/
public function get direction():String
{
return _direction;
} /**
* @private
*/
public function set direction(value:String):void
{
_direction = value;
} /**
* 手指或者鼠标滑动的实际矢量距离(有方向)
*/
public function get slidingDis():Number
{
return _slidingDis;
}
/**
* 当手指或者鼠标划过的距离大于这个值时才识别为翻页
*/
public function get slidingNum():Number
{
return _slidingNum;
} /**
* @private
*/
public function set slidingNum(value:Number):void
{
_slidingNum = value;
} }
}

[ActionScript 3.0] AS3 用于拖动对象时一次一页的缓动的更多相关文章

  1. [ActionScript 3.0] AS3 用于拖动对象时跟随鼠标的缓动效果

    package com.fylibs.components.effects { import flash.display.DisplayObject; import flash.events.Even ...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. [ActionScript 3.0] AS3 深入理解Flash的 应用程序域Application Domains

    简介 网上有很多flash,通常都不需要显示的使用应用程序域,因为默认的应用程序域就够用了.其实复杂的情况下需要用到应用程序域,比如说有两个不同的swf,一个是旧版本的,一个是新版的,这两个文件里的类 ...

随机推荐

  1. JQuery高性能最佳实践

    [使用最佳选择器] 使用JQuery时,你可以使用多种选择器,选择同一个元素,各种方法之间的性能是不一样的,有时候差异会特别大. 通常比较常用的选择器有以下几个: ID选择器 $("#id& ...

  2. shell脚本实例-游戏脚本

    http://bbs.chinaunix.net/thread-3580033-1-1.html shell游戏收集贴 #!/bin/bash # Tetris Game #APP declarati ...

  3. unity vr sample on htc vive

    http://forum.unity3d.com/threads/unity-vr-samples-now-available.372753/

  4. 微软发布了ASP.NET WebHooks预览版

    微软 近期发布了ASP.NET WebHooks的预览版 ,这是一个可用于创建及使用Webhook功能的库.WebHooks支持MVC 5及WebApi 2. Webhook是一种通过HTTP实现用户 ...

  5. javascript中href和replace比较

      在使用javascript的时候,有时候对于经常使用的方法太熟悉而忽略了他们之间原理的细微差别.举例如下:window.location.href,window.location.replace. ...

  6. 通过命令行安装Android app

    手动安装安卓app的命令为:adb install -r C:\Users\Lihao\workspace\Appium_Demo\apps\app_F_1.3.0.apk

  7. mybatis migrate常用指令

    0.制定db和配置文件 --path=xxx --env=dev 1.初始化Migrations工作目录 migrate init 2.创建数据库变更 migrate new "liyq a ...

  8. 类找不到异常 Caused by: java.lang.NoClassDefFoundError

    错误原因:在部署应用的时候,服务器报错,Caused by: java.lang.ClassNotFoundException: org.quartz.impl.JobDetailImpl,某个类找不 ...

  9. 转:java日志组件介绍(common-logging,log4j,slf4j,logback )

    原网址:http://www.blogjava.net/daiyongzhi/archive/2014/04/13/412364.html common-logging common-logging是 ...

  10. Hive(七):HQL DML

    HQL DML 主要涉到对Hive表中数据操作,包含有:load.INSERT.DELETE.EXPORT and IMPORT,详细资料参见:https://cwiki.apache.org/con ...