永发信息网

flash 鼠标拖动 影片剪辑前进和后退问题

答案:1  悬赏:60  手机版
解决时间 2021-01-29 22:51
  • 提问者网友:寂寞梧桐
  • 2021-01-29 08:55
flash 鼠标拖动 影片剪辑前进和后退 我想让拖动反应区域在图片范围内 但是不知道代码怎么打
现在的代码是
a1.stop();

// 鼠标数据。
var startMouseX = 0;
//var startMouseY = 0;
var lastMouseX = 0;
//var lastMouseY = 0;
// 是否正在按下状态。
var isDown = false;

// 一帧需移动10像素。
var onceFrameNeedMove = 10;

a11.onMouseDown = function() {
var mouseX = _root._xmouse;
//var mouseY = _root._ymouse;
startMouseX = mouseX;
//startMouseY = mouseY;
lastMouseX = mouseX;
//lastMouseY = mouseY;
isDown = true;
}
a11.onMouseMove = function() {
if(!isDown){return;}
var mouseX = _root._xmouse;
//var mouseY = _root._ymouse;
var moveX = mouseX - lastMouseX;
if(Math.abs(moveX) >= onceFrameNeedMove){
lastMouseX = mouseX;
if (moveX > 0)
{
_root.a1.nextFrame();
}
else
{
_root.a1.prevFrame();
}
}
}
a11.onMouseUp = function() {
isDown = false;
}

这个是SWF的地址
http://pan.baidu.com/s/1kUsp4uN

谁能帮我补充下代码或者更容易的代码 要AS2的 感谢
最佳答案
  • 五星知识达人网友:舍身薄凉客
  • 2021-01-29 10:34
写了一个元件绑定类,绑定到影片剪辑上就具有拖动跳帧功能了


class com.set2get.as2.view.McDragPlay extends MovieClip
{
private var _mouseX:Number = 0;
private var _mouseY:Number = 0;
private var _baseFrame:Number = 0;

private var _dragLength:Number = 15;

private var _Root:MovieClip;


private var _isDebug:Boolean = false;
private var _debugText:TextField;
public function McDragPlay() 
{
super();
init();
}

private function init():Void {
onPress = onDown_func;
onRelease = onReleaseOutside = onUp_func;
}

private function initDebug():Void {
_debugText = this.createTextField("tDebug", this.getNextHighestDepth(), 0, 0, 1, 1);
_debugText._x = 30;
_debugText._y = 60;
_debugText.autoSize = "left";
}

private function onUp_func():Void 
{
delete this.onMouseMove;
}

private function onDown_func():Void 
{
_mouseX = int(_Root._xmouse);
_mouseY = int(_Root._ymouse);
_baseFrame = _currentframe;
onMouseMove = onMouseMove_func
}

private function onMouseMove_func():Void 
{
var _diff:Number = _Root._xmouse - _mouseX; //计算坐标差
var _tFrame:Number = int(_diff / _dragLength); //计算偏移帧数 正或负
var _tEndFrame:Number = (_totalframes + ((_baseFrame + _tFrame) % _totalframes)) % _totalframes + 1;
//基准帧+偏移量+总帧数 取模总帧数,修正加1,就是目标帧数
this.gotoAndStop(_tEndFrame);
if (_isDebug) {
_debugText.text = _tEndFrame + "";
}
}


public function set isDebug(value:Boolean):Void 
{
_isDebug = value;
if (value && !_debugText) initDebug();
}


public function set dragLength(value:Number):Void 
{
if (value < 1) return;
_dragLength = value;
}

public function set root(value:MovieClip):Void {
_Root = value;
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯