[ActionScript 3.0] AS3 用于拖动对象时一次一页的缓动
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 用于拖动对象时一次一页的缓动的更多相关文章
- [ActionScript 3.0] AS3 用于拖动对象时跟随鼠标的缓动效果
package com.fylibs.components.effects { import flash.display.DisplayObject; import flash.events.Even ...
- [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.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) ...
- [ActionScript 3.0] AS3 深入理解Flash的安全沙箱Security Domains
简介 如果你还没有与复杂的的安全域(security domain)和应用程序域(application domain)问题打过交道,那么你真是个幸运的家伙.当你在加载外部内容(然后他们开始播放)的时 ...
- [ActionScript 3.0] AS3 深入理解Flash的 应用程序域Application Domains
简介 网上有很多flash,通常都不需要显示的使用应用程序域,因为默认的应用程序域就够用了.其实复杂的情况下需要用到应用程序域,比如说有两个不同的swf,一个是旧版本的,一个是新版的,这两个文件里的类 ...
随机推荐
- Python_Day_5装饰器、字符串格式化、序列化、内置模块、生成器、迭代器之篇
一.装饰器 为什么要用装饰器??? 在实际的开发环境中应遵循开发封闭原则,虽然在这个原则是用的面向对象开发,但也适用于函数式编程,简单地说,它规定已经实现的功能代码不是允许修改的,但是可以被扩展: 封 ...
- shell之eval-command
本文将会讲解一些linux中命令的使用与技巧希望对新手给予帮助一 e v a l命令将会首先扫描命令行进行所有的置换,然后再执行该命令.该命令适用于那些一次扫描无法实现其功能的变量.该命令对变量进行两 ...
- unity, 保存prefab时material丢失问题
在程序运行时用replacePrefab(gameObj,prefab)或createPrefab(gameObj,prefab)保存prefab,遇到保存出来的prefab中material丢失的问 ...
- java中的堆、栈、常量池以及String类型的两种声明
参考自http://blog.sina.com.cn/s/blog_798b04f90100ta67.html http://www.cnblogs.com/fguozhu/articles/2661 ...
- apache2: Could not reliably determine the server's fully qualified domain name
错误信息:apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 ...
- postman使用教程
最近很多朋友在问postman的使用方法,现我经过整理,分享给大家. Postman 是一个很强大的 API调试.Http请求的工具,当你还准备拿着记事本傻傻的去写 Form 表单的时候,你来试试 P ...
- Java compiler level does not match the version of the installed Java project facet.问题
从同事那里拷贝过来的web项目,导入到eclipse中,出现Java compiler level does not match the version of the installed Java p ...
- uboot 环境变量
从bootm 命令讲起 1 找到linux的内核入口 Bootm命令通过读取uImage的头部0×40字节的信息,将uImage定位到正确的地址,同时找到linux的内核入口地址. 这个地方就涉及到u ...
- W81安装记录
安装Windows 8.1之前先断网!!! 在x86的WinPE环境中安装Windows 8.1 x64的方法: 1.格式化硬盘的第一主分区C盘,将x64的ISO解压到其他分区里: 2.复制ISO解压 ...
- SpringMVC参数类型转化错误调试方法