点击并通过框架AS3拖

编程入门 行业动态 更新时间:2024-10-24 22:23:19
本文介绍了点击并通过框架AS3拖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一帧一帧动画。我希望能够通过动画点击并在舞台上来回拖动和移动。即我想点击,并从左至右,使动画向前走,并从右向左拖动,使动画倒退。

I have a frame-by-frame animation. I want to be able to click and drag on the stage back and forth and traverse through the animation. I.e. I want to click and drag from left to right to make the animation go forwards and right to left to make the animation go backwards.

我将如何实现这一目标?

How would I achieve this?

我想提出一个假设,即会有一些数学参与计算鼠标位置,并穿越到正确的框架,但我将如何做到这一点?

I am making an assumption that there will be some maths involved in calculating mouse position and traversing to the correct frame, but how would I do this?

推荐答案

在这里,您有(编辑的版本)

Here you are (edited version)

import flash.events.MouseEvent; import flash.display.MovieClip; import flash.display.Sprite; var clickedMouseX:int; var clickedFrame:uint; var backgroundClip:Sprite = getChildByName("background") as Sprite; var clip:MovieClip = getChildByName("animation") as MovieClip; clip.stop(); clip.mouseEnabled = false; backgroundClip.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); backgroundClip.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); function onMouseDown(event:MouseEvent):void { backgroundClip.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove); clickedMouseX = backgroundClip.mouseX; clickedFrame = clip.currentFrame; } function onMouseUp(event:MouseEvent):void { backgroundClip.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove); } function onMouseMove(event:MouseEvent):void { var delta:int = backgroundClip.mouseX - clickedMouseX; var wantedFrame:uint = (clickedFrame + delta * clip.totalFrames / backgroundClip.width) % clip.totalFrames; while (wantedFrame < 1) { wantedFrame += clip.totalFrames; } clip.gotoAndStop(wantedFrame); }

干杯!

更多推荐

点击并通过框架AS3拖

本文发布于:2023-11-23 15:45:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622003.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:框架

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!