ActionScript3.0实现动态地图效果

14年的一个项目需求,研究了一下AS脚本。AS2.0是之前面向关系的语言,AS3.0之后开始走上面向对象路线。

现在附上当时的代码,里边包含很多细节和算法,重要的代码也都有注释,如果需要可以仔细看一下

stop();
//固定打开窗口
fscommand("allowscale", false);//是否允许缩放
fscommand("showmenu", false);
//fscommand("fullscreen", "true");//是否全屏播放
Stage.scaleMode = "noScale";//舞台显示模式
//Stage.align="T"
this["souma"].useHandCursor = false;
this["souma"].buttonMode = true;
//全屏隐藏
QPQH._visible=false;quanping._visible=false;
MA._visible=false;
Mouse.hide();
mx.behaviors.DepthControl.bringToFront(_root.quantou);
mx.behaviors.DepthControl.bringToFront(_root.normal_hand);
//参数设置
var PlusD:Number=20.5;//滑块最大值距离增大元件位置16
var SubtrD:Number=20.5;//滑块最小值距离增小元件位置17
//鼠标移动跟踪
var mouseListener = new Object();
mouseListener.onMouseMove = function() {
    quantou._x = normal_hand._x = _xmouse;
    quantou._y =normal_hand._y = _ymouse;
};
Mouse.addListener(mouseListener);
//全屏提示显示管理
QPXS._visible=true;TCQP._visible=false;

var mn:ContextMenu = new ContextMenu();//新建一个菜单对象替换默认的
//禁用右键菜单
mn.hideBuiltInItems();
mn.onSelect = function() {//当菜单显示时
onMouseMove =  function(){//定义鼠标移动时触发函数(只有菜单不显示时才会触发哦);
Mouse.hide();//隐藏鼠标;
onMouseMove = function(){
normal_hand._x = _xmouse;
normal_hand._y = _ymouse;
quantou._x = _xmouse;
quantou._y = _ymouse;
        };
    };
};
_root.menu = mn;//替换默认右键菜单

//移出舞台
import flash.filters.BlurFilter;
function mouseMoveOutScreen() {
    stopDrag();
delete souma.onEnterFrame;
normal_hand._visible = false;
quantou._visible = false;
}
//移入舞台
function mouseMoveInScreen() {
    Mouse.hide();
normal_hand._visible = true;
onMouseMove = function () {
    normal_hand._x = _xmouse;
    normal_hand._y = _ymouse;
    quantou._x = _xmouse;
    quantou._y = _ymouse;
};
quantou._visible = false;
}

MouseCheck.init(25,mouseMoveOutScreen,mouseMoveInScreen);
//开始检测
MouseCheck.startListen();
//方向按键移入
button_mc.onPress=button_mc.onRelease=button_mc.onRollOver=function(){;
Mouse.show();
this.useHandCursor=false;
normal_hand._visible=false;
onMouseMove = function(){ ;
normal_hand._x = _xmouse;
normal_hand._y = _ymouse;
quantou._x = _xmouse;
quantou._y = _ymouse;
};
quantou._visible=false;
};

//地图按下
this["souma"].onPress  = function() {
    //获取移动souma前point
var SoumaX:Number=souma._x;
var SoumaY:Number=souma._y;
//获取云的位置
var yun1x:Number=yun1._x;
var yun1y:Number=yun1._y;
var yun2x:Number=yun2._x;
var yun2y:Number=yun2._y;
var pubux:Number=pubu._x;
var pubuy:Number=pubu._y;

var MCpointX:Array = new Array();
var MCpointY:Array = new Array();
for (var d:Number = 1; d<=31; d++) {
    MCpointX[d]=_root["pic"+d+"_mc"]._x;
    MCpointY[d]=_root["pic"+d+"_mc"]._y;
    }
normal_hand._visible = false;
//trace("["+souma._x+","+souma._y+"]AND mouse【"+_xmouse+""+_ymouse+"】");
onMouseMove = function () {
    quantou._x = normal_hand._x = _xmouse;
    quantou._y =normal_hand._y = _ymouse;
};
quantou._visible = true;//

    //souma.startDrag(false,1640,250,-650,350);
    souma.startDrag();
    souma.onEnterFrame = function() {
        //超出拖动范围
        if(souma._x<(souma._width - Stage.width)*-1)
        souma._x=(souma._width - Stage.width)*-1;
        if(souma._y<(souma._height - Stage.height)*-1)
        souma._y=(souma._height - Stage.height)*-1;
        if(souma._x>0)
        souma._x=0;
        if(souma._y>0)
        souma._y=0;

        var bool:Boolean=false;
        pubu._x=souma._x-SoumaX+pubux;
        pubu._y=souma._y-SoumaY+pubuy;
        yun1._x=souma._x-SoumaX+yun1x;
        yun1._y=souma._y-SoumaY+yun1y;
        yun2._x=souma._x-SoumaX+yun2x;
        yun2._y=souma._y-SoumaY+yun2y;
for (var i:Number = 1; i<=31; i++) {
_root["pic"+i+"_mc"]._x = souma._x-SoumaX+MCpointX[i];
_root["pic"+i+"_mc"]._y = souma._y-SoumaY+MCpointY[i];
if(i==31)bool=true;
}        

        //响应松开
if(bool==true)
{
_root.onMouseUp = function() {
quantou._visible = false;
Mouse.hide();
onMouseMove = function () {
    normal_hand._x = _xmouse;
    normal_hand._y = _ymouse;
    quantou._x = _xmouse;
    quantou._y = _ymouse;
};
normal_hand._visible = true;
stopDrag();
        };
}        

};
//

};

//子集建筑元件
for (var d:Number = 1; d<=31; d++) {
//元件按下事件
this["pic"+d+"_mc"].onPress = function() {
//显示当前元件为最前
//mx.behaviors.DepthControl.bringToFront(this);
this.onEnterFrame = function() {
current = this._name.slice(this._name.indexOf("c")+1, this._name.indexOf("_"));
//this._xscale += (150-this._xscale)/6;
//this._yscale += (150-this._yscale)/6;
//if (this._xscale>=150) {
//    delete this.onEnterFrame;
//}
this.gotoAndPlay(2);
};
};

//元件松开事件
this["pic"+d+"_mc"].onRelease = function() {
this.onEnterFrame = function() {
//this._xscale -= (this._xscale-100)/6;
//this._yscale -= (this._yscale-100)/6;
//if (this._xscale<100) {
//    delete this.onEnterFrame;
//}
this.gotoAndPlay(2);
};
quantou._visible = false;
normal_hand._visible = false;
Mouse.show();
onMouseMove = function () {
    normal_hand._x = _xmouse;
    normal_hand._y = _ymouse;
    quantou._x = _xmouse;
    quantou._y = _ymouse;
};
if(current<=13||current==25||current==24||current==28||current==30||current==31)//1-13  24 25  28 30 31
getURL("http://e.51somabs.com:8080/WebPage/CourseType.aspx?info="+current,"_bank");
//getURL("WebPage/CourseType.aspx?info="+current,"_bank");

//getURL("javascript:window.open(‘CourseType.aspx?info="+current+"‘)");

};

//元件移入事件
this["pic"+d+"_mc"].onRollOver = function() {
normal_hand._visible = false;
quantou._visible = false;
//加载外部图片
//this.loadMovie("beidouxing_light.png");
onMouseMove = function () {
    normal_hand._x = _xmouse;
    normal_hand._y = _ymouse;
    quantou._x = _xmouse;
    quantou._y = _ymouse;
};
this.onEnterFrame = function() {
//this._xscale -= (this._xscale-100)/6;
//this._yscale -= (this._yscale-100)/6;
//if (this._xscale<100) {
//    delete this.onEnterFrame;
//}
this.gotoAndPlay(2);
};
Mouse.show();
};
//元件移出事件
this["pic"+d+"_mc"].onRollOut = function() {
normal_hand._visible = true;
onMouseMove = function () {
    normal_hand._x = _xmouse;
    normal_hand._y = _ymouse;
    quantou._x = _xmouse;
    quantou._y = _ymouse;
};
this.onEnterFrame = function() {
this.gotoAndPlay(1);
};
Mouse.hide();
};
//按下元件移出
this["pic"+d+"_mc"].onReleaseOutside =function()
{
    normal_hand._visible = true;
onMouseMove = function () {
    normal_hand._x = _xmouse;
    normal_hand._y = _ymouse;
    quantou._x = _xmouse;
    quantou._y = _ymouse;
};
this.onEnterFrame = function() {
//this._xscale -= (this._xscale-100)/6;
//this._yscale -= (this._yscale-100)/6;
//if (this._xscale<100) {
//    delete this.onEnterFrame;
//}
this.gotoAndPlay(1);
}
    }

}
//方向键移出
button_mc.onRollOut = function() {
Mouse.hide();
normal_hand._visible = true;
onMouseMove = function () {
    normal_hand._x = _xmouse;
    normal_hand._y = _ymouse;
    quantou._x = _xmouse;
    quantou._y = _ymouse;
};
quantou._visible = false;
};
//btn键入
huakuai.onPress=huakuai.onRollOver=quanping.onPress=quanping.onRollOver=
btnSubstract.onPress=btnSubstract.onRelease=btnSubstract.onRollOver=
btnadd.onPress=btnadd.onRelease=btnadd.onRollOver=
btnadd.onPress=btnadd.onRelease=btnadd.onRollOver=
btn_down.onPress=btn_down.onRelease=btn_down.onRollOver=
btn_left.onPress=btn_left.onRelease=btn_left.onRollOver=
btn_right.onPress=btn_right.onRelease=btn_right.onRollOver=
btn_up.onRelease=btn_up.onRollOver=function(){
Mouse.show();
//this.useHandCursor=false;
normal_hand._visible=false;
onMouseMove = function(){
normal_hand._x = _xmouse;
normal_hand._y = _ymouse;
quantou._x = _xmouse;
quantou._y = _ymouse;

};
quantou._visible=false;
};
//Dragmodel状态
UDLR.onPress=UDLR.onRelease=UDLR.onRollOver=dragModel.onPress=dragModel.onRelease=dragModel.onRollOver=function(){
Mouse.show();
this.useHandCursor=false;
normal_hand._visible=false;
onMouseMove = function(){
normal_hand._x = _xmouse;
normal_hand._y = _ymouse;
quantou._x = _xmouse;
quantou._y = _ymouse;
    };
}
//移出方向和dragModel鼠标状态
UDLR.onRollOut=dragModel.onRollOut=function(){
    Mouse.hide();
    normal_hand._visible=true;
onMouseMove = function(){
normal_hand._x = _xmouse;
normal_hand._y = _ymouse;
quantou._x = _xmouse;
quantou._y = _ymouse;
    };
    }

//向上
btn_up.onPress=function(){
var count:Number=0;
        _root.onEnterFrame=function(){
        //下移动超出
            if(souma._y<0&&count<15)
            {
                var Move:Number=10;//移动距离
                var Dvalue:Number=souma._y*-1;//距离最大移动量的距离差
                if(Dvalue>Move)
                {
                souma._y+=Move;
                yun1._y+=Move;
                yun2._y+=Move;
                pubu._y+=Move;
                for (var i:Number = 1; i<=31; i++) {
                _root["pic"+i+"_mc"]._y +=Move;
                    }
                }
                else
                {
                souma._y+=Dvalue;
                yun1._y+=Dvalue;
                yun2._y+=Dvalue;
                pubu._y+=Dvalue;
                for (var i:Number = 1; i<=31; i++) {
                _root["pic"+i+"_mc"]._y +=Dvalue;
                    }
                    delete _root.onEnterFrame;
                }
            count++;
            }
        }
};

//向下
btn_down.onPress=function(){
    var count:Number=0;
        _root.onEnterFrame=function(){
        //上移动超出
            if(souma._y>(souma._height - Stage.height)*-1&&count<15)
            {
                var Move:Number=10;//移动距离
                var Dvalue:Number=souma._y-((souma._height - Stage.height)*-1);//距离最大移动量的距离差
                if(Dvalue>Move)
                {
                souma._y-=Move;
                yun1._y-=Move;
                yun2._y-=Move;
                pubu._y-=Move;
                for (var i:Number = 1; i<=31; i++) {
                _root["pic"+i+"_mc"]._y -=Move;
                    }
                }
                else
                {
                souma._y-=Dvalue;
                yun1._y-=Dvalue;
                yun2._y-=Dvalue;
                pubu._y-=Dvalue;
                for (var i:Number = 1; i<=31; i++) {
                _root["pic"+i+"_mc"]._y -=Dvalue;
                    }
                    delete _root.onEnterFrame;
                }
            count++;
            }
        }

};
//向左
btn_left.onPress=function(){
    var count:Number=0;
        _root.onEnterFrame=function(){
        //右移动超出
            if(souma._x<0&&count<20)
            {
                var Move:Number=10;//移动距离
                var Dvalue:Number=souma._x*-1;//距离最大移动量的距离差
                if(Dvalue>Move)
                {
                souma._x+=Move;
                yun1._x+=Move;
                yun2._x+=Move;
                pubu._x+=Move;
                for (var i:Number = 1; i<=31; i++) {
                _root["pic"+i+"_mc"]._x +=Move;
                    }
                }
                else
                {
                souma._x+=Dvalue;
                yun1._x+=Dvalue;
                yun2._x+=Dvalue;
                pubu._x+=Dvalue;
                for (var i:Number = 1; i<=31; i++) {
                _root["pic"+i+"_mc"]._x +=Dvalue;
                    }
                    delete _root.onEnterFrame;
                }
            count++;
            }
        }
};
//向右
btn_right.onPress=function(){
    var count:Number=0;
        _root.onEnterFrame=function(){
        //左移动超出
            if(souma._x>(souma._width - Stage.width)*-1&&count<20)
            {
                var Move:Number=10;//移动距离
                var Dvalue:Number=souma._x-((souma._width - Stage.width)*-1);//距离最大移动量的距离差
                if(Dvalue>Move)
                {
                souma._x-=Move;
                yun1._x-=Move;
                yun2._x-=Move;
                pubu._x-=Move;
                for (var i:Number = 1; i<=31; i++) {
                _root["pic"+i+"_mc"]._x -=Move;
                    }
                }
                else
                {
                souma._x-=Dvalue;
                yun1._x-=Dvalue;
                yun2._x-=Dvalue;
                pubu._x-=Dvalue;
                for (var i:Number = 1; i<=31; i++) {
                _root["pic"+i+"_mc"]._x -=Dvalue;
                    }
                    delete _root.onEnterFrame;
                }
            count++;
            }
        }
};

//鼠标滚轮事件
Mouse.addListener(this);
//确定最大最小缩放比例
var scale_max:Number=100;
var scale_min:Number=55;
//进行放大缩小前鼠标位置
var tempX:Number;
var tempY:Number;
//移动前各品牌位置差
var MCMoveX:Array = new Array();
var MCMoveY:Array = new Array();
for (var d:Number = 1; d<=31; d++) {
    //移动前各个品牌位置差
    MCMoveX[d]=_root["pic"+d+"_mc"]._x - _root["souma"]._x;
    MCMoveY[d]=_root["pic"+d+"_mc"]._y - _root["souma"]._y;
}
//云未移动前位置
var yunMove1x:Number=yun1._x - _root["souma"]._x;
var yunMove1y:Number=yun1._y - _root["souma"]._y;
var yunMove2x:Number=yun2._x - _root["souma"]._x;
var yunMove2y:Number=yun2._y - _root["souma"]._y;
//瀑布未移动前位置
var pubuMovex:Number=pubu._x -_root["souma"]._x;
var pubuMovey:Number=pubu._y -_root["souma"]._y;
//触发事件
onMouseWheel=function(delta){
    //获取缩放前鼠标位置
tempX=souma._xmouse;
tempY=souma._ymouse;

      var sca:Number = _root["souma"]._xscale + (delta > 0?15: -15);
     _root["huakuai"]._y += (delta > 0?-34: 34);
      if (sca > scale_max)
      {sca = scale_max;
        _root["huakuai"]._y=_root["btnadd"]._y+PlusD;}
      if (sca < scale_min)
      {sca = scale_min;
       _root["huakuai"]._y=_root["btnSubstract"]._y-SubtrD;}//最大位置需Y轴平移96
      //定位滑块一、最大1位置904.2,201.2】二、最大1位置904.2,232.2】三、最大1位置904.2,270.2】四、最大1位置904.2,298.2       y; 117.2  149.2  181.2  213.2       X 1235.2
       //缩放地图
      _root["souma"]._xscale = _root["souma"]._yscale =sca;
        //根据鼠标的位置比例  和  地图的当前尺寸 重新定义地图的坐标
        _root["souma"]._x=_root._xmouse-tempX * souma._xscale/100;
        _root["souma"]._y=_root._ymouse-tempY * souma._yscale/100;
        //超出拖动范围
        if(souma._x<(souma._width - Stage.width)*-1)
        souma._x=(souma._width - Stage.width)*-1;
        if(souma._y<(souma._height - Stage.height)*-1)
        souma._y=(souma._height - Stage.height)*-1;
        if(souma._x>0)
        souma._x=0;
        if(souma._y>0)
        souma._y=0;
    //清除拖动EnterFrame
      delete souma.onEnterFrame;
      //云同比缩放
       pubu._xscale=pubu._yscale=yun1._xscale=yun1._yscale=yun2._xscale=yun2._yscale=sca;
       yun1._x=_root["souma"]._x + ( yunMove1x * _root["souma"]._xscale /100 );
       yun1._y=_root["souma"]._y + ( yunMove1y * _root["souma"]._yscale /100 );
       yun2._x=_root["souma"]._x + ( yunMove2x * _root["souma"]._xscale /100 );
       yun2._y=_root["souma"]._y + ( yunMove2y * _root["souma"]._yscale /100 );
       //瀑布同比缩放
       pubu._x=_root["souma"]._x + ( pubuMovex * _root["souma"]._xscale /100 );
       pubu._y=_root["souma"]._y + ( pubuMovey * _root["souma"]._yscale /100 );
      //品牌同比缩放
        for (var mc:Number = 1; mc<=31; mc++) {
        _root["pic"+mc+"_mc"]._xscale=_root["pic"+mc+"_mc"]._yscale=sca;
        _root["pic"+mc+"_mc"]._x =_root["souma"]._x + ( MCMoveX[mc] * _root["souma"]._xscale /100 );
        _root["pic"+mc+"_mc"]._y =_root["souma"]._y + ( MCMoveY[mc] * _root["souma"]._yscale /100 );
    }
}

//按键实现放大缩小
//缩放
btnSubstract.onPress=function(){
    this.onEnterFrame=function(){this.gotoAndPlay(2);}
    _root["huakuai"]._y+=(_root["btnSubstract"]._y-_root["huakuai"]._y>SubtrD?34:0);//在滑块距离减号距离大于最小比例位置时自增32
    //获取缩放前鼠标位置
tempX=souma._xmouse;
tempY=souma._ymouse;
      var sca:Number = _root["souma"]._xscale -15;
      if (sca > scale_max)
      {sca = scale_max;
        _root["huakuai"]._y=_root["btnadd"]._y+PlusD;}
      if (sca < scale_min)
      {sca = scale_min;
       _root["huakuai"]._y=_root["btnSubstract"]._y-SubtrD;}//最大位置需Y轴平移96
       //缩放地图
       souma._yscale=souma._xscale=sca;
        //根据鼠标的位置比例  和  地图的当前尺寸 重新定义地图的坐标
        _root["souma"]._x=_root._xmouse-tempX * souma._xscale/100;
        _root["souma"]._y=_root._ymouse-tempY * souma._yscale/100;
        //超出拖动范围
        if(souma._x<(souma._width - Stage.width)*-1)
        souma._x=(souma._width - Stage.width)*-1;
        if(souma._y<(souma._height - Stage.height)*-1)
        souma._y=(souma._height - Stage.height)*-1;
        if(souma._x>0)
        souma._x=0;
        if(souma._y>0)
        souma._y=0;
    //清除拖动EnterFrame
      delete souma.onEnterFrame;
      //云、瀑布同比缩放
      pubu._xscale=pubu._yscale=yun1._xscale=yun1._yscale=yun2._xscale=yun2._yscale=sca;
       yun1._x=_root["souma"]._x + ( yunMove1x * _root["souma"]._xscale /100 );
       yun1._y=_root["souma"]._y + ( yunMove1y * _root["souma"]._yscale /100 );
       yun2._x=_root["souma"]._x + ( yunMove2x * _root["souma"]._xscale /100 );
       yun2._y=_root["souma"]._y + ( yunMove2y * _root["souma"]._yscale /100 );
        //瀑布同比缩放
       pubu._x=_root["souma"]._x + ( pubuMovex * _root["souma"]._xscale /100 );
       pubu._y=_root["souma"]._y + ( pubuMovey * _root["souma"]._yscale /100 );
      //品牌同比缩放
        for (var mc:Number = 1; mc<=31; mc++) {
        _root["pic"+mc+"_mc"]._xscale=_root["pic"+mc+"_mc"]._yscale=sca;
        _root["pic"+mc+"_mc"]._x =_root["souma"]._x + ( MCMoveX[mc] * _root["souma"]._xscale /100 );
        _root["pic"+mc+"_mc"]._y =_root["souma"]._y + ( MCMoveY[mc] * _root["souma"]._yscale /100 );
    }
}
//放大
btnadd.onPress=function(){
    this.onEnterFrame=function(){this.gotoAndPlay(2);}
    _root["huakuai"]._y -=(_root["huakuai"]._y-root["btnadd"]._y<PlusD?0:34);
    //获取缩放前鼠标位置
tempX=souma._xmouse;
tempY=souma._ymouse;
      var sca:Number = _root["souma"]._xscale +15;
      if (sca > scale_max)
      {sca = scale_max;
       _root["huakuai"]._y=_root["btnadd"]._y+PlusD;}
      if (sca < scale_min)
      {sca = scale_min;
       _root["huakuai"]._y=_root["btnSubstract"]._y-SubtrD;}//最大位置需Y轴平移96
       //缩放地图
       souma._yscale=souma._xscale=sca;
        //根据鼠标的位置比例  和  地图的当前尺寸 重新定义地图的坐标
        _root["souma"]._x=_root._xmouse-tempX * souma._xscale/100;
        _root["souma"]._y=_root._ymouse-tempY * souma._yscale/100;
        //超出拖动范围
        if(souma._x<(souma._width - Stage.width)*-1)
        souma._x=(souma._width - Stage.width)*-1;
        if(souma._y<(souma._height - Stage.height)*-1)
        souma._y=(souma._height - Stage.height)*-1;
        if(souma._x>0)
        souma._x=0;
        if(souma._y>0)
        souma._y=0;
    //清除拖动EnterFrame
      delete souma.onEnterFrame;
      //云、瀑布同比缩放
      pubu._xscale=pubu._yscale=yun1._xscale=yun1._yscale=yun2._xscale=yun2._yscale=sca;
       yun1._x=_root["souma"]._x + ( yunMove1x * _root["souma"]._xscale /100 );
       yun1._y=_root["souma"]._y + ( yunMove1y * _root["souma"]._yscale /100 );
       yun2._x=_root["souma"]._x + ( yunMove2x * _root["souma"]._xscale /100 );
       yun2._y=_root["souma"]._y + ( yunMove2y * _root["souma"]._yscale /100 );
        //瀑布同比缩放
       pubu._x=_root["souma"]._x + ( pubuMovex * _root["souma"]._xscale /100 );
       pubu._y=_root["souma"]._y + ( pubuMovey * _root["souma"]._yscale /100 );
      //品牌同比缩放
        for (var mc:Number = 1; mc<=31; mc++) {
        _root["pic"+mc+"_mc"]._xscale=_root["pic"+mc+"_mc"]._yscale=sca;
        _root["pic"+mc+"_mc"]._x =_root["souma"]._x + ( MCMoveX[mc] * _root["souma"]._xscale /100 );
        _root["pic"+mc+"_mc"]._y =_root["souma"]._y + ( MCMoveY[mc] * _root["souma"]._yscale /100 );
    }
}

//滑块拖动事件
huakuai.onPress=function (){
    //定位滑块一、最大1位置904.2,201.2】二、最大1位置904.2,232.2】三、最大1位置904.2,270.2】四、最大1位置904.2,298.2
    //huakuai.startDrag(false,905,200,905,300);
    huakuai.startDrag(false,Stage.width-126.8+70,_root["btnadd"]._y+PlusD ,Stage.width-126.8+70,_root["btnadd"]._y+PlusD+103);
    }
//滑块移动
    var pointHK:Number;//滑块y坐标
    //舞台鼠标弹起事件
someListener.onMouseUp = huakuai.onRelease=function(){
    huakuai.stopDrag();
    Mouse.show();
    normal_hand._visible=false;
    onMouseMove = function(){
    normal_hand._x = _xmouse;
    normal_hand._y = _ymouse;
    quantou._x = _xmouse;
    quantou._y = _ymouse;
    }
    pointHK=huakuai._y;
    var Point1:Number=Math.abs(pointHK - (_root["btnadd"]._y+PlusD));
    var Point2:Number=Math.abs(pointHK - (_root["btnadd"]._y+PlusD+34));
    var Point3:Number=Math.abs(pointHK - (_root["btnadd"]._y+PlusD+34+34));
    var Point4:Number=Math.abs(pointHK - (_root["btnadd"]._y+34+34+34));
    var Point12:Number=(Point1<Point2?Point1:Point2);
    var Point34:Number=(Point3<Point4?Point3:Point4);
    var PointMin:Number=Point12<Point34?Point12:Point34;
    if(PointMin==Point1){
    huakuai._y=_root["btnadd"]._y+PlusD;
    changeScale(100);
    //超出拖动范围
        if(souma._x<(souma._width - Stage.width)*-1)
        souma._x=(souma._width - Stage.width)*-1;
        if(souma._y<(souma._height - Stage.height)*-1)
        souma._y=(souma._height - Stage.height)*-1;
        if(souma._x>0)
        souma._x=0;
        if(souma._y>0)
        souma._y=0;
    }
    else if (PointMin==Point2){
    huakuai._y=_root["btnadd"]._y+PlusD+34;
    changeScale(85);
    //超出拖动范围
        if(souma._x<(souma._width - Stage.width)*-1)
        souma._x=(souma._width - Stage.width)*-1;
        if(souma._y<(souma._height - Stage.height)*-1)
        souma._y=(souma._height - Stage.height)*-1;
        if(souma._x>0)
        souma._x=0;
        if(souma._y>0)
        souma._y=0;
    }
    else if (PointMin==Point3){
    huakuai._y=_root["btnadd"]._y+PlusD+34+34;
    changeScale(70);
    //超出拖动范围
        if(souma._x<(souma._width - Stage.width)*-1)
        souma._x=(souma._width - Stage.width)*-1;
        if(souma._y<(souma._height - Stage.height)*-1)
        souma._y=(souma._height - Stage.height)*-1;
        if(souma._x>0)
        souma._x=0;
        if(souma._y>0)
        souma._y=0;
    }
    else if (PointMin==Point4){
    huakuai._y=_root["btnadd"]._y+PlusD+34+34+34;
    changeScale(55);
    //超出拖动范围
        if(souma._x<(souma._width - Stage.width)*-1)
        souma._x=(souma._width - Stage.width)*-1;
        if(souma._y<(souma._height - Stage.height)*-1)
        souma._y=(souma._height - Stage.height)*-1;
        if(souma._x>0)
        souma._x=0;
        if(souma._y>0)
        souma._y=0;    

    }
}
//鼠标按下移开滑块,清楚拖动
_root["huakuai"].onReleaseOutside=function(){
    _root["huakuai"].stopDrag();
    }
    //缩放方法
function changeScale(scale:Number){

        tempX=souma._xmouse;
        tempY=souma._ymouse;
      var sca:Number = _root["souma"]._xscale =scale;
      if (sca > scale_max)
      {sca = scale_max;
       _root["huakuai"]._y=_root["btnadd"]._y+PlusD;}
      if (sca < scale_min)
      {sca = scale_min;
       _root["huakuai"]._y=_root["btnSubstract"]._y-SubtrD;}//最大位置需Y轴平移96
       //缩放地图
      _root["souma"]._xscale = _root["souma"]._yscale =sca;
        //根据鼠标的位置比例  和  地图的当前尺寸 重新定义地图的坐标
        _root["souma"]._x=_root._xmouse-tempX * souma._xscale/100;
        _root["souma"]._y=_root._ymouse-tempY * souma._yscale/100;
    //清除拖动EnterFrame
      delete souma.onEnterFrame;
      //云、瀑布同比缩放
      pubu._xscale=pubu._yscale=yun1._xscale=yun1._yscale=yun2._xscale=yun2._yscale=sca;
       yun1._x=_root["souma"]._x + ( yunMove1x * _root["souma"]._xscale /100 );
       yun1._y=_root["souma"]._y + ( yunMove1y * _root["souma"]._yscale /100 );
       yun2._x=_root["souma"]._x + ( yunMove2x * _root["souma"]._xscale /100 );
       yun2._y=_root["souma"]._y + ( yunMove2y * _root["souma"]._yscale /100 );
        //瀑布同比缩放
       pubu._x=_root["souma"]._x + ( pubuMovex * _root["souma"]._xscale /100 );
       pubu._y=_root["souma"]._y + ( pubuMovey * _root["souma"]._yscale /100 );
      //品牌同比缩放
        for (var mc:Number = 1; mc<=31; mc++) {
        _root["pic"+mc+"_mc"]._xscale=_root["pic"+mc+"_mc"]._yscale=sca;
        _root["pic"+mc+"_mc"]._x =_root["souma"]._x + ( MCMoveX[mc] * _root["souma"]._xscale /100 );
        _root["pic"+mc+"_mc"]._y =_root["souma"]._y + ( MCMoveY[mc] * _root["souma"]._yscale /100 );
    }
}
//窗口大小改变
var myListener:Object = new Object();
myListener.onResize = function () {
    //onEnterFrame=function(){
        //定位鼠标位置
quantou._x = normal_hand._x = _xmouse;
quantou._y =normal_hand._y = _ymouse;
//定位全屏按钮
quanping._x=50;
quanping._y=60;
//提示文字位置18.75,99.1
//QPXS._x=90;
//QPXS._y=25;
//TCQP._x=90;
//TCQP._Y=25;
QPQH._x=90;
QPQH._y=25;
btn_up._x=Stage.width-127.1+70;
//btn_up._y=Stage.height-554.05-20;
btn_right._x=Stage.width-110.25+70;
//btn_right._y=Stage.height-535.7-20;
btn_down._x=Stage.width-128.5+70;
//btn_down._y=Stage.height-518-20;
btn_left._x=Stage.width-145.35+70;
//btn_left._y=Stage.height-536.85-20;
UDLR._x=Stage.width-127.8+70;
//UDLR._y=Stage.height-535.7-20;
dragModel._x=Stage.width-126.45+70;
//dragModel._y=Stage.height-426.95-20;
btnSubstract._x=Stage.width-126.6+70;
//btnSubstract._y=Stage.height-360.9-20;
btnadd._x=Stage.width-126.65+70;
//btnadd._y=Stage.height-490.55-20;
huakuai._x=Stage.width-126.8+70;
//switch(souma._xscale)
//{
//    case 100:
//    //huakuai._y=Stage.height-474.8-20;
//    //huakuai._y=huakuai._y;
//    break;
//    case 85:
//    //huakuai._y=Stage.height-474.8-20+32;
//    //huakuai._y+=32;
//    break;
//    case 70:
//    //huakuai._y=Stage.height-474.8-20+32+32;
//    //huakuai._y+=64;
//    break;
//    case 55:
//    //huakuai._y=Stage.height-474.8-20+32+32+32;
//    //huakuai._y+=96;
//    break;
//    }
    //超出拖动范围
        if(souma._x<(souma._width - Stage.width)*-1)
        souma._x=(souma._width - Stage.width)*-1;
        if(souma._y<(souma._height - Stage.height)*-1)
        souma._y=(souma._height - Stage.height)*-1;
        if(souma._x>0)
        souma._x=0;
        if(souma._y>0)
        souma._y=0;

    //}

}
Stage.addListener(myListener);
myListener.onResize();
//quanping._alpha=50;
//添加全屏按钮事件
quanping.onPress=quanping.onRollOver=function(){
normal_hand._visible=false;
Mouse.show();
    quantou._x = normal_hand._x = _xmouse;
    quantou._y =normal_hand._y = _ymouse;
    //onEnterFrame=function(){
//        if(quanping._alpha<100){
//        quanping._alpha+=5;}
//        else
//       delete this.onEnterFrame;
//      }
    }
quanping.onRollOut=function(){
    Mouse.hide();
    quantou._x = normal_hand._x = _xmouse;
    quantou._y =normal_hand._y = _ymouse;
    normal_hand._visible=true;
    //onEnterFrame=function(){
//         if(quanping._alpha>50){
//        quanping._alpha-=5;
//         }
//         else
//       delete this.onEnterFrame;
//        }
    }
quanping.onRelease =function(){
    Stage["displayState"] = Stage["displayState"] == "normal" ? "fullScreen" : "normal";
    if(Stage["displayState"] == "normal"){
    //Mouse.show();normal_hand._visible=false;QPXS._visible=true;TCQP._visible=false;
    }
    else{
        MA._visible=false;
    //QPXS._visible=false;TCQP._visible=true;Mouse.hide();
    }
    quantou._x = normal_hand._x = _xmouse;
    quantou._y =normal_hand._y = _ymouse;    

    };//128.35  233.35

//trace(_root["QPXS"]._y+","+_root["QPXS"]._x);
//键盘ESC按下退出全屏
//Key.addListener({onKeyDown:function(){
//     if(Key.getCode() == Key.ESCAPE){
//    Stage["displayState"] = Stage["displayState"] == "normal" ? "fullScreen" : "normal";
//        if(Stage["displayState"] == "fullScreen")
//        {
//        Stage["displayState"] = "normal";
//        QPXS._visible=true;TCQP._visible=false;
//        }
//     }
//     }});

对于一些大的flash加载添加进度条是少不了的进度条,如何根据实际加载进度去显示加载进度,请看以下代码:

stop(); //第一帧停止//
//固定打开窗口
fscommand("allowscale", false);//是否允许缩放
fscommand("showmenu", false);
//fscommand("fullscreen", "true");//是否全屏播放
Stage.scaleMode = "noScale";//舞台显示模式

stop ();
var bytestotal = 0;
var bytesloaded = 0;
var fr = 0;
this.onEnterFrame = function ()
{
    bytestotal = _root.getBytesTotal();
    bytesloaded = _root.getBytesLoaded();
    fr = bytesloaded / bytestotal;
    this.preloader.SetProgress(fr);
    if (bytesloaded >= bytestotal)
    {
        delete this.onEnterFrame;
        play ();
    } // end if
};

获取鼠标操作事件

这里可以直接将鼠标操作封装为面向对象的类文件MouseCheck.as,可以直接在fla文件中引用

import flash.geom.*;
class MouseCheck {
    private static var rect:Rectangle;
    private static var out:Boolean;
    private static var m_pos:Point;
    private static var old_m_pos:Point;
    private static var out_val:Number;
    private static var _val:Number;
    private static var out_func:Function;
    private static var in_func:Function;
    private static var frame:Number;
    private static var border:Number;
    private static function onResize() {
        rect = new Rectangle(border, border, Stage.width-border*2, Stage.height-border*2);
        //trace(rect);
    }
    public static function init(_frame:Number, out_f:Function, in_f:Function) {
        Stage.scaleMode = "noScale";
        Stage.align = "TL";
        Stage.addListener(MouseCheck);
        border = 1;
        /////////
        rect = new Rectangle(border, border, Stage.width-border*2, Stage.height-border*2);
        m_pos = new Point(_root._xmouse, _root._ymouse);
        frame = 1000/_frame;
        out_func = out_f;
        in_func = in_f;
        /////////
        if (!rect.containsPoint(m_pos)) {
            out_func();
            out = true;
        } else {
            in_func();
            out = false;
        }
    }
    private static function cheekOut() {
        old_m_pos = m_pos.clone();
        m_pos = new Point(_xmouse, _ymouse);
        if (!m_pos.equals(old_m_pos)) {
            var n_pos:Point = new Point(m_pos.x+(m_pos.x-old_m_pos.x)*1.1, m_pos.y+(m_pos.y-old_m_pos.y)*1.1);
            if (rect.containsPoint(n_pos)) {
                if (out) {
                    out = false;
                    in_func();
                    trace("mouse move in  screen");
                }
                if (out_val) {
                    clearInterval(out_val);
                }
            } else {
                clearInterval(out_val);
                delete out_val;
                out_val = setInterval(timeOut, frame*3);
            }
        }
    }
    private static function timeOut() {
        var old_d = m_pos.clone();
        m_pos = new Point(_xmouse, _ymouse);
        if (m_pos.equals(old_d) && !out) {
            out = true;
            out_func();
            trace("mouse move out screen");
        }
        clearInterval(out_val);
        delete out_val;
    }
    public static function startListen() {
        trace("start listen");
        clearInterval(_val);
        delete _val;
        _val = setInterval(cheekOut, frame);
    }
    public static function clearListen() {
        clearInterval(_val);
        delete _val;
    }
    function MouseCheck() {
    }
}
时间: 2024-10-05 21:35:52

ActionScript3.0实现动态地图效果的相关文章

原创教程“ActionScript3.0游戏中的图像编程”开始连载啦!

        经过近两年的不懈努力,笔者的原创教程“ActionScript3游戏中的图像编程”终于在今日划上了完美的句号!这当中记录着笔者多年来在游戏制作,尤其是当中图像处理方面的经验心得.虽然使用的语言是目前可能正在没落的ActionScript3.0,但由于其中渗透着深刻的编程思想和实用技巧,因此其意义已经远远超越了ActionScript本身.您可以把从本书学到的知识轻松移植到其他支持图像编程的开发语言中(我也想换个语言重写,可惜精力不足).         此外,本书还包含了一些颜色

原创图书《ActionScript3.0游戏中的图像编程》开始连载啦!

        经过近两年的不懈努力,笔者的原创图书<ActionScript3游戏中的图像编程>终于在今日划上了完美的句号!这当中记录着笔者多年来在游戏制作,尤其是当中图像处理方面的经验心得.虽然使用的语言是目前可能正在没落的ActionScript3.0,但由于其中渗透着深刻的编程思想和实用技巧,因此其意义已经远远超越了ActionScript本身.您可以把从本书学到的知识轻松移植到其他支持图像编程的开发语言中(我也想换个语言重写,可惜精力不足).         此外,本书还包含了一些颜

[原创图书]《ActionScript3.0游戏中的图像编程》连载——前言

1946年,计算机在第三次工业革命的推动下得以诞生并发展.从此地球上多了一类人,他们的世界很简单,每天不是和0接触,就是跟1来往.他们低调做人,高调做事,他们务实为民,不求名利,他们,就是可爱可人,可歌可泣的IT工作者--程序员! 都说程序员不善表达,没错,离开0和1,程序员就几乎不会说话了.与此同时,程序员也恰恰是最善于表达的人,他们只用0和1这两个数字,就可以准确无误地将用户的需求传达给电脑并使其正确运行,其语言之简炼,其算法之精准,其逻辑之严谨,其结果之准确,试问除了程序员,还有谁可以做得

【ActionScript】ActionScript3.0的Helloworld

虽然说ActionScript2.0与ActionScript3.0熟练使用任意一门都可以,但是ActionScript3.0带来了许多新的开发感受.新时代的Flash已经开始向ActionScript3.0转型,许多新的Flash框架与Flash资料都是基于ActionScript3.0.所以还是两门双修好勒.ActionScript2.0的Helloworld已经在<[ActionScript]ActionScript2.0的Helloworld>(点击打开链接)中介绍过了.下面开始介绍A

ActionScript3.0教你在影片剪辑中访问主场景中的变量

在ActionScript2.0中,影片剪辑访问主场景中的变量非常的简单,仅仅需要用一个带有_root的绝对路径即可. 然而在ActionScript3.0影片剪辑中访问主场景中的变量却没有那么容易,使用root将会报错.下面为大家介绍一种非常简单的方法来访问主场景中的变量. 方法如下: 1.在MC(影片剪辑实例名称)里定义一个变量father:Object; 2.在主场景代码中进行赋值 MC.father = this; 3.在影片剪辑里访问的时候就直接 father.变量名 就行.

ActionScript3.0(AS3)中的泛型数组Vector

Adobe官方并没有"泛型数组"的叫法,这是我自己对Vector的叫法(有点标题党),不过Vector在使用上确实跟c#中的泛型数组有些相似之处. 原作者:菩提树下的杨过出处:http://yjmyzz.cnblogs.com 我们知道:ActionScript3.0中的Array数组可以存放多种类型,甚至在同一个Array数组中,可以同时存入String,Object,Number...,但其实我们在实际开发中,通常一个数组中所保存的元素类型都是一致的,为了改进这种情况下的效率,AS

Android 高仿 QQ5.0 侧滑菜单效果 自定义控件来袭【学习鸿洋_视频博客笔记总结】

学习鸿洋博客:http://blog.csdn.net/lmj623565791/article/details/39257409 学习鸿洋视频:慕课网视频 看看Android 高仿 QQ5.0 侧滑菜单效果 自定义控件实现效果: 技术上,继承HorizontalScrollView 加上自定义ViewGroup来实现: 1.onMeasure:决定内部View(子View)的宽和高,以及自己的宽和高 2.onLayout:决定子View的放置位置 3.onTouchEvent[监听动作] 自定

使用DrawerLayout实现QQ5.0侧拉菜单效果

在上一篇文章中,我们介绍了怎么使用DrawerLayout来实现一个简单的侧拉菜单(使用DrawerLayout实现侧拉菜单),也就是我们常说的抽屉效果,GitHub上类似效果的实现方式非常多,实现出来的效果也是非常的绚丽,但是万变不离其宗,Google提供给我们的DrawerLayout才是最基本的,我们今天就来介绍一下怎样通过DrawerLayout来实现QQ5.0的侧拉效果.先来看一张效果图: 好,这是一个我们即将要实现的效果图,关于这个效果,大部分都是很简单的,都是使用了我们在上一篇博客

Android 4.0以上BlurMaskFilter效果无效

Android MaskFilter的基本使用: MaskFilter类可以为Paint分配边缘效果.        对MaskFilter的扩展可以对一个Paint边缘的alpha通道应用转换.Android包含了下面几种MaskFilter: BlurMaskFilter   指定了一个模糊的样式和半径来处理Paint的边缘.        EmbossMaskFilter  指定了光源的方向和环境光强度来添加浮雕效果. 要应用一个MaskFilter,可以使用setMaskFilter方法