请高人指点!怎么把下面这段AS2.0代码翻译成AS3.0的?(是移动鼠标改变物体X坐标)
onClipEvent(enterFrame){if(_root.mainVar==0){homeX=-_root._xmouse*3.500000E-001+300;}...
onClipEvent (enterFrame)
{
if (_root.mainVar == 0)
{
homeX = -_root._xmouse * 3.500000E-001 + 300;
}
else
{
homeX = -_root.mainVar * 3 + 1400;
} // end else if
thisX = _x;
diffX = homeX - thisX;
if (_root.mainVar == 0)
{
moveX = diffX / 30;
}
else
{
moveX = diffX / 22;
} // end else if
setProperty("", _x, thisX + moveX);
} 展开
{
if (_root.mainVar == 0)
{
homeX = -_root._xmouse * 3.500000E-001 + 300;
}
else
{
homeX = -_root.mainVar * 3 + 1400;
} // end else if
thisX = _x;
diffX = homeX - thisX;
if (_root.mainVar == 0)
{
moveX = diffX / 30;
}
else
{
moveX = diffX / 22;
} // end else if
setProperty("", _x, thisX + moveX);
} 展开
2个回答
2011-09-23
展开全部
var mc1:MovieClip = this.myMC1;
var mc2:MovieClip = this.myMC2;
//记录MC的尺寸
var mcW:Number = mc1._width;
var mcH:Number = mc1._height;
//记录屏幕尺寸
var sw:Number = Stage.width;
var sh:Number = Stage.height;
//设置MC可移动的边界
var topM:Number = 0 + mcH * .5;
var buttonM:Number = sh - mcH * .5;
var leftM:Number = 0 + mcW * .5;
var rightM:Number = sw - mcW * .5;
//设置MC移动速度
var spX:Number;
var spY:Number;
function MoveMyMC(tar:MovieClip)
{
//随机移动:
spX = (Math.random() * sw - tar._x) / 5;
spY = (Math.random() * sh - tar._y) / 5;
tar.spX = spX;
tar.spY = spY;
//设置MC临时XY
var tx:Number;
var ty:Number;
tar.onEnterFrame = function()
{
//记录MC的XY
tx = tar._x;
ty = tar._y;
//改变MC的XY
tx += this.spX;
ty += this.spY;
//检测边界:
if (tx > rightM) {
//右边
tx = rightM;
}
if (tx < leftM) {
//左边
tx = leftM;
}
if (ty < topM) {
//上边
ty = topM;
}
if (ty > buttonM) {
//下边
ty = buttonM;
}
//更新MC位置:
this._x = tx;
this._y = ty;
};
}
this.onMouseDown = function()
{
//如果只有一个MC移动,只要使用一个就可以了:
MoveMyMC(mc1);
MoveMyMC(mc2);
};
var mc2:MovieClip = this.myMC2;
//记录MC的尺寸
var mcW:Number = mc1._width;
var mcH:Number = mc1._height;
//记录屏幕尺寸
var sw:Number = Stage.width;
var sh:Number = Stage.height;
//设置MC可移动的边界
var topM:Number = 0 + mcH * .5;
var buttonM:Number = sh - mcH * .5;
var leftM:Number = 0 + mcW * .5;
var rightM:Number = sw - mcW * .5;
//设置MC移动速度
var spX:Number;
var spY:Number;
function MoveMyMC(tar:MovieClip)
{
//随机移动:
spX = (Math.random() * sw - tar._x) / 5;
spY = (Math.random() * sh - tar._y) / 5;
tar.spX = spX;
tar.spY = spY;
//设置MC临时XY
var tx:Number;
var ty:Number;
tar.onEnterFrame = function()
{
//记录MC的XY
tx = tar._x;
ty = tar._y;
//改变MC的XY
tx += this.spX;
ty += this.spY;
//检测边界:
if (tx > rightM) {
//右边
tx = rightM;
}
if (tx < leftM) {
//左边
tx = leftM;
}
if (ty < topM) {
//上边
ty = topM;
}
if (ty > buttonM) {
//下边
ty = buttonM;
}
//更新MC位置:
this._x = tx;
this._y = ty;
};
}
this.onMouseDown = function()
{
//如果只有一个MC移动,只要使用一个就可以了:
MoveMyMC(mc1);
MoveMyMC(mc2);
};
2011-09-22
展开全部
比如有一个MovieClip,它是有位置坐标的。然后当你鼠标点击的时候,也有一个坐标,这个时候你就可以在EnterFrame事件中去慢慢改变这个MovieClip的坐标,以达到移动的效果。
具体的实现,可以联系我。
具体的实现,可以联系我。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询