flash iphone效果

 

  1. package MyTouchApp
  2. {
  3. import flash.display.DisplayObject;
  4. import flash.display.Shape;
  5. import flash.display.Sprite;
  6. import flash.events.Event;
  7. import flash.events.MouseEvent;
  8. import flash.geom.Point;
  9. /**
  10. * TapScroller simulates iPhone like scrolling.
  11. */
  12. public class TapScroller extends Sprite
  13. {
  14. private var _content:DisplayObject; // Inner contents 内在的内容
  15. private var _scrollBarV:Sprite; // MovieClip of scroll bars 影片剪辑的滚动条
  16. private var _scrollBarH:Sprite;
  17. public var scrollFactor:Number = 10; // 滚动因素是鼠标拖动移动长度检测 10 Scroll factor is length of mouse movement to detect dragging
  18. public var useVertical:Boolean = true; //使用垂直滚动条 use vertical scrolling
  19. public var useHorizontal:Boolean = true; //使用水平滚动条 use horizontal scrolling
  20. private var isDragging:Boolean = false; // 拖动标记 dragging flag
  21. private var lastPos:Point = new Point(); // 最后鼠标位置 last mouse position
  22. private var firstPos:Point = new Point(); // 首先鼠标位置 first mouse position
  23. private var firstPanelPos:Point = new Point(); // 小组首先在鼠标位置 first mouse position in panel
  24. private var diff:Point = new Point(); // 不同的鼠标移动 difference of mouse movement
  25. private var inertia:Point = new Point(); // 滚动inhertia力量 scroll inhertia power
  26. private var min:Point = new Point(); // 最小的移动的长度 minimum movable length
  27. private var max:Point = new Point(); // 最大的移动的长度 maximum movable length
  28. private var panelWidth:Number;
  29. private var panelHeight:Number;
  30. public function TapScroller(content:DisplayObject,width:Number, height:Number)
  31. {
  32. // copy size
  33. panelWidth = width;
  34. panelHeight = height;
  35. // 填补空虚的立方体,宽度和高度 fill empty rectangle with width and height
  36. graphics.beginFill(0, 0);
  37. graphics.drawRect(0, 0, width, height);
  38. graphics.endFill();
  39. _content = content;
  40. addChild(content);
  41. addEventListener(Event.ADDED_TO_STAGE, handleAddedToStage);
  42. // initialize mask
  43. var mask:Shape = new Shape();
  44. mask.graphics.beginFill(0, 1);
  45. mask.graphics.drawRect(0,0,width, height);
  46. mask.graphics.endFill();
  47. addChild(mask);
  48. _content.mask = mask;
  49. // initialize scrollbar
  50. _scrollBarV = new Sprite();
  51. _scrollBarV.cacheAsBitmap = true;
  52. _scrollBarV.x = width - 10;
  53. addChild(_scrollBarV);
  54. _scrollBarH = new Sprite();
  55. _scrollBarH.cacheAsBitmap = true;
  56. _scrollBarH.y = height - 10;
  57. addChild(_scrollBarH);
  58. }
  59. /**
  60. * Get contents
  61. */
  62. public function get content():DisplayObject {
  63. return _content;
  64. }
  65. /**
  66. * Listener for stage addition
  67. * @param e event
  68. */
  69. private function handleAddedToStage(e:Event):void {
  70. addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown);
  71. addEventListener(Event.ENTER_FRAME, handleEnterFrame);
  72. removeEventListener(Event.ADDED_TO_STAGE, handleAddedToStage);
  73. }
  74. /**
  75. * Listener for mouse movement
  76. * @param e information for mouse
  77. */
  78. private function handleMouseMove(e:MouseEvent):void {
  79. var totalX:Number = mouseX - firstPos.x;
  80. var totalY:Number = mouseY - firstPos.y;
  81. // movement detection with scrollFactor
  82. if (useVertical && Math.abs(totalY) > scrollFactor) {
  83. isDragging = true;
  84. }
  85. if (useHorizontal && Math.abs(totalX) > scrollFactor) {
  86. isDragging = true;
  87. }
  88. if (isDragging) {
  89. if (useVertical) {
  90. if (totalY < min.y) {
  91. totalY = min.y - Math.sqrt(min.y-totalY);
  92. }
  93. if (totalY > max.y) {
  94. totalY = max.y + Math.sqrt(totalY - max.y);
  95. }
  96. _content.y = firstPanelPos.y + totalY;
  97. }
  98. if (useHorizontal) {
  99. if (totalX < min.x) {
  100. totalX = min.x - Math.sqrt(min.x-totalX);
  101. }
  102. if (totalX > max.x) {
  103. totalX = max.x + Math.sqrt(totalX - max.x);
  104. }
  105. _content.x = firstPanelPos.x + totalX;
  106. }
  107. 0
声明:OSCHINA 博客文章版权属于作者,受法律保护。未经作者同意不得转载。
最新热门职位
更多开发者职位上 开源中国·招聘
  • flash iphone效果
    网页设计师 澳煦互动
    月薪: 6-9K
  • flash iphone效果
    嵌入式软件工程师 橙鲜科技
    月薪: 10-15K
  • flash iphone效果
    web前端 中企九胜
    月薪: 3-8K
  • flash iphone效果
    存储高级开发工程师 金山云
    月薪: 20-40K

评论

  • 楼: () 手机 Android iPhone Windows Phone 微信 发表于 删除 回复此评论
  • 1

插入: 表情 开源软件

山哥

发表评论 插入: 表情 开源软件

关闭插入表情
关闭相关文章阅读
  • 2014/08/19 Flash移动开发高级教程——创建Anr...
  • 2013/01/23 iphone4抖动效果源码
  • 2012/03/14 flash
  • 2013/09/04 FusionCharts使用JavaScript渲染iPh...
  • 2013/05/28 flash RadioButton基本值...

你可能感兴趣的:(flash iphone效果)