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实现动态地图效果的更多相关文章
- 原创教程“ActionScript3.0游戏中的图像编程”開始连载啦!
经过近两年的不懈努力,笔者的原创教程"ActionScript3游戏中的图像编程"最终在今日划上了完美的句号!这其中记录着笔者多年来在游戏制作,尤其是其中图像处理方 ...
- AxureRP7.0各类交互效果汇总帖(转)
了便于大家参考,我把这段时间发布分享的所有关于AxureRP7.0的原型做了整理. 以下资源均有对应的RP源文件可以下载. 当然 ,其中有部分是需要通过完成解密游戏[攻略]才能得到下载地址或者下载密码 ...
- css3.0新属性效果在ie下的解决方案(兼容性)
css3.0增加的新属性,如投影.渐变.旋转.圆角等等!这些新标准属性在ie6.ie7.ie8浏览器版本里得不到很好的支持,相信ie以后的新版本也会支持这些新属性的.目前ie6.ie7.ie8浏览器不 ...
- 【转】Cocos2d-x 2.0 拖尾效果深入分析
Cocos2d-x 2.0 拖尾效果深入分析 另:本章所用Cocos2d-x版本为: cocos2d-2.0-x-2.0.2@ Aug 30 2012 http://cn.cocos2d-x.org/ ...
- 使用DrawerLayout实现QQ5.0侧拉菜单效果
在上一篇文章中,我们介绍了怎么使用DrawerLayout来实现一个简单的侧拉菜单(使用DrawerLayout实现侧拉菜单),也就是我们常说的抽屉效果,GitHub上类似效果的实现方式非常多,实现出 ...
- 【ActionScript】ActionScript3.0对舞台组件的增删改查
以一个样例来说明ActionScript3.0对舞台组件的增删改查 例如以下图: 在Flash执行的时候,通过脚本.斜向下生成text0-text9十个文本节点. 提供两个功能. 1.在右上角,用户输 ...
- ActionScript3.0(AS3)中的泛型数组Vector
Adobe官方并没有"泛型数组"的叫法,这是我自己对Vector的叫法(有点标题党),不过Vector在使用上确实跟c#中的泛型数组有些相似之处. 原作者:菩提树下的杨过出处:ht ...
- Vue.2.0.5-过渡效果
概述 Vue 在插入.更新或者移除 DOM 时,提供多种不同方式的应用过渡效果.包括以下工具: 在 CSS 过渡和动画中自动应用 class 可以配合使用第三方 CSS 动画库,如 Animate.c ...
- [ActionScript 3.0] AS3.0 水面波纹效果
import flash.geom.Point; import flash.display.BitmapData; import flash.filters.DisplacementMapFilter ...
随机推荐
- PAT-7-14 电话聊天狂人
ps: 真不明白为什么水题不能一次ac 7-14 电话聊天狂人(25 分) 给定大量手机用户通话记录,找出其中通话次数最多的聊天狂人. 输入格式: 输入首先给出正整数N(≤105),为通话记录条 ...
- tomcat服务器安装方法
tomcat: 链接:https://pan.baidu.com/s/1pMEu0hP 密码:g0ah (tomcat7) jdk :链接:https://pan.baidu.com/s/1 ...
- mysql设置更改root密码、mysql服务器的连接、mysql常用命令
1.设置更改root密码 查看mysql 启动与否,若没启动就运行:/usr/local/mysql56/bin/mysqlps aux |grep mysql 或 netstat -tulnp ...
- 重写ajax方法实现请求session过期时跳转登录页面
jQuery(function($){ var _ajax=$.ajax; // 备份jquery的ajax方法 $.ajax=function(opt){ var _success = opt &a ...
- url中携带中文乱码问题
1.问题描述 在项目中碰见url中经常传递中文参数时,容易出现乱码问题,现在就这个问题产生原因和解决的措施大概分析一下,希望过路人和我能引以为戒. 2.问题分析 由于我们利用URL传递参数这种方式是依 ...
- 【HAOI2008】圆上的整点
数学题 原题:平面上有一个圆, 圆心坐标为(0,0),半径为n. 问圆周上有多少个整点. 整点的定义即x,y坐标均为整数的点. 这根本就是一道数学题,注意是数学题,不是数论,数学! 纯粹就看魔性变公式 ...
- 如何将centos7作为DNS服务器
简单来说,dns服务器是起到缓存的作用.比如说我们第一次dig www.baidu.com的时候,dns服务器因为没有解析过百度地址,所以它需要向上一级dns服务器进行查询,然后查询结果会缓存在这台d ...
- Nginx配置基于ip的虚拟主机
我是在centos7虚拟机上进行实验的 该实验基于添加好ip的基础上,如何给网卡添加ip请查阅我的博客 先来看一下我的ip [root@localhost nginx]# ifconfig ens33 ...
- 02c语言指针基础
& 用来取一个变量的地址 * 用来取一个地址的值 例如: (1)&n 获取n的地址 int *p=&n; *p就等于p的值 (2) 假设 int n=10; *(&n) ...
- xcrun: error: invalid active developer path
问题 mac升级到10.12(macOS Sierra),执行命令,出现如下错误: xcrun: error: invalid active developer path (/Library/Deve ...