ActionScript3.0实现动态地图效果
Posted loyung
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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() { } }
以上是关于ActionScript3.0实现动态地图效果的主要内容,如果未能解决你的问题,请参考以下文章