打印

[基础] 元件随鼠标左右上下的效果怎么做呢?

请问:我现在需要做这样一个效果,我的场景大小是:1000×600,上面有一元件1900×1024,我想当鼠标左右上下移动时,元件在场景范围内左右上下移动…请问怎么做呢?论坛上有这类的教程吗?谢谢…
onmousemove事件
使元件的坐标位置与鼠标位置相关
谢谢2楼,但是能详细一点吗?我刚接触as,还不是很熟悉…希望你看着代码然后查帮助学习…
我写过一个,看看对你有帮助没?
复制内容到剪贴板
代码:
//记录舞台的长宽
var w:Number = Stage.width;
var h:Number = Stage.height;
//背景mc的长宽,也就是你的1900*1024
var bg_w:Number = back._width;
var bg_h:Number = back._height;
//计算鼠标位置到边界的距离所占舞台的百分比
var xscale:Number = (bg_w-w)/w;
var yscale:Number = (bg_h-h)/h;
//移动速度
var speed:Number = 50;
onEnterFrame = function () {
    //开始移动
    back._x += (-_xmouse*xscale-back._x)/speed;
    back._y += (-_ymouse*yscale-back._y)/speed;
};
拉家登舍

TOP

还在为头像烦恼?还在为不能关注好友动态烦忧?快来蓝色理想家园吧!
元件名为showimg,注册点为左上角
_root.onMouseMove=function(){
              left=0
              right=1000
              up=0
              down=600
              if(_xmouse>left&&_xmouse<right&&_ymouse>up&&_ymouse<down){
              //移动控制
              showimg._x-=(_xmouse-right/2)/10
              showimg._y-=(_ymouse-down/2)/10
              //限定移动范围
              if(showimg._x>left){
                     showimg._x=left
                     }
              if(showimg._y>up){
                     showimg._y=up
              }
              if(showimg._x<right-showimg._width){
                     showimg._x=right-showimg._width
                     }
              if(showimg._y<down-showimg._height){
                     showimg._y=down-showimg._height
              }
              }
              updataAfterEvent()
              }//end onmousemove

[ 本帖最后由 SUNXINZHE 于 2008-6-23 18:14 编辑 ]

TOP

谢谢楼上两位朋友…我这就练习一下

TOP

function move_func() {
        _mc.onEnterFrame = function () {
            var _local3 = (Stage.width / 2) - _xmouse;
            var _local2 = (Stage.height / 2) - _ymouse;
            this._x = this._x + ((_local3 - this._x) / 5);
            this._y = this._y + ((_local2 - this._y) / 5);
        };
    }
    move_func();

这个比较简单
   _mc就是你要移动的MC
design888

TOP

关注

关注

TOP