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

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

  1. stop();
  2. //固定打开窗口
  3. fscommand("allowscale", false);//是否允许缩放
  4. fscommand("showmenu", false);
  5. //fscommand("fullscreen", "true");//是否全屏播放
  6. Stage.scaleMode = "noScale";//舞台显示模式
  7. //Stage.align="T"
  8. this["souma"].useHandCursor = false;
  9. this["souma"].buttonMode = true;
  10. //全屏隐藏
  11. QPQH._visible=false;quanping._visible=false;
  12. MA._visible=false;
  13. Mouse.hide();
  14. mx.behaviors.DepthControl.bringToFront(_root.quantou);
  15. mx.behaviors.DepthControl.bringToFront(_root.normal_hand);
  16. //参数设置
  17. var PlusD:Number=20.5;//滑块最大值距离增大元件位置16
  18. var SubtrD:Number=20.5;//滑块最小值距离增小元件位置17
  19. //鼠标移动跟踪
  20. var mouseListener = new Object();
  21. mouseListener.onMouseMove = function() {
  22. quantou._x = normal_hand._x = _xmouse;
  23. quantou._y =normal_hand._y = _ymouse;
  24. };
  25. Mouse.addListener(mouseListener);
  26. //全屏提示显示管理
  27. QPXS._visible=true;TCQP._visible=false;
  28.  
  29. var mn:ContextMenu = new ContextMenu();//新建一个菜单对象替换默认的
  30. //禁用右键菜单
  31. mn.hideBuiltInItems();
  32. mn.onSelect = function() {//当菜单显示时
  33. onMouseMove = function(){//定义鼠标移动时触发函数(只有菜单不显示时才会触发哦);
  34. Mouse.hide();//隐藏鼠标;
  35. onMouseMove = function(){
  36. normal_hand._x = _xmouse;
  37. normal_hand._y = _ymouse;
  38. quantou._x = _xmouse;
  39. quantou._y = _ymouse;
  40. };
  41. };
  42. };
  43. _root.menu = mn;//替换默认右键菜单
  44.  
  45. //移出舞台
  46. import flash.filters.BlurFilter;
  47. function mouseMoveOutScreen() {
  48. stopDrag();
  49. delete souma.onEnterFrame;
  50. normal_hand._visible = false;
  51. quantou._visible = false;
  52. }
  53. //移入舞台
  54. function mouseMoveInScreen() {
  55. Mouse.hide();
  56. normal_hand._visible = true;
  57. onMouseMove = function () {
  58. normal_hand._x = _xmouse;
  59. normal_hand._y = _ymouse;
  60. quantou._x = _xmouse;
  61. quantou._y = _ymouse;
  62. };
  63. quantou._visible = false;
  64. }
  65.  
  66. MouseCheck.init(25,mouseMoveOutScreen,mouseMoveInScreen);
  67. //开始检测
  68. MouseCheck.startListen();
  69. //方向按键移入
  70. button_mc.onPress=button_mc.onRelease=button_mc.onRollOver=function(){;
  71. Mouse.show();
  72. this.useHandCursor=false;
  73. normal_hand._visible=false;
  74. onMouseMove = function(){ ;
  75. normal_hand._x = _xmouse;
  76. normal_hand._y = _ymouse;
  77. quantou._x = _xmouse;
  78. quantou._y = _ymouse;
  79. };
  80. quantou._visible=false;
  81. };
  82.  
  83. //地图按下
  84. this["souma"].onPress = function() {
  85. //获取移动souma前point
  86. var SoumaX:Number=souma._x;
  87. var SoumaY:Number=souma._y;
  88. //获取云的位置
  89. var yun1x:Number=yun1._x;
  90. var yun1y:Number=yun1._y;
  91. var yun2x:Number=yun2._x;
  92. var yun2y:Number=yun2._y;
  93. var pubux:Number=pubu._x;
  94. var pubuy:Number=pubu._y;
  95.  
  96. var MCpointX:Array = new Array();
  97. var MCpointY:Array = new Array();
  98. for (var d:Number = 1; d<=31; d++) {
  99. MCpointX[d]=_root["pic"+d+"_mc"]._x;
  100. MCpointY[d]=_root["pic"+d+"_mc"]._y;
  101. }
  102. normal_hand._visible = false;
  103. //trace("["+souma._x+","+souma._y+"]AND mouse【"+_xmouse+""+_ymouse+"】");
  104. onMouseMove = function () {
  105. quantou._x = normal_hand._x = _xmouse;
  106. quantou._y =normal_hand._y = _ymouse;
  107. };
  108. quantou._visible = true;//
  109.  
  110. //souma.startDrag(false,1640,250,-650,350);
  111. souma.startDrag();
  112. souma.onEnterFrame = function() {
  113. //超出拖动范围
  114. if(souma._x<(souma._width - Stage.width)*-1)
  115. souma._x=(souma._width - Stage.width)*-1;
  116. if(souma._y<(souma._height - Stage.height)*-1)
  117. souma._y=(souma._height - Stage.height)*-1;
  118. if(souma._x>0)
  119. souma._x=0;
  120. if(souma._y>0)
  121. souma._y=0;
  122.  
  123. var bool:Boolean=false;
  124. pubu._x=souma._x-SoumaX+pubux;
  125. pubu._y=souma._y-SoumaY+pubuy;
  126. yun1._x=souma._x-SoumaX+yun1x;
  127. yun1._y=souma._y-SoumaY+yun1y;
  128. yun2._x=souma._x-SoumaX+yun2x;
  129. yun2._y=souma._y-SoumaY+yun2y;
  130. for (var i:Number = 1; i<=31; i++) {
  131. _root["pic"+i+"_mc"]._x = souma._x-SoumaX+MCpointX[i];
  132. _root["pic"+i+"_mc"]._y = souma._y-SoumaY+MCpointY[i];
  133. if(i==31)bool=true;
  134. }
  135.  
  136. //响应松开
  137. if(bool==true)
  138. {
  139. _root.onMouseUp = function() {
  140. quantou._visible = false;
  141. Mouse.hide();
  142. onMouseMove = function () {
  143. normal_hand._x = _xmouse;
  144. normal_hand._y = _ymouse;
  145. quantou._x = _xmouse;
  146. quantou._y = _ymouse;
  147. };
  148. normal_hand._visible = true;
  149. stopDrag();
  150. };
  151. }
  152.  
  153. };
  154. //
  155.  
  156. };
  157.  
  158. //子集建筑元件
  159. for (var d:Number = 1; d<=31; d++) {
  160. //元件按下事件
  161. this["pic"+d+"_mc"].onPress = function() {
  162. //显示当前元件为最前
  163. //mx.behaviors.DepthControl.bringToFront(this);
  164. this.onEnterFrame = function() {
  165. current = this._name.slice(this._name.indexOf("c")+1, this._name.indexOf("_"));
  166. //this._xscale += (150-this._xscale)/6;
  167. //this._yscale += (150-this._yscale)/6;
  168. //if (this._xscale>=150) {
  169. // delete this.onEnterFrame;
  170. //}
  171. this.gotoAndPlay(2);
  172. };
  173. };
  174.  
  175. //元件松开事件
  176. this["pic"+d+"_mc"].onRelease = function() {
  177. this.onEnterFrame = function() {
  178. //this._xscale -= (this._xscale-100)/6;
  179. //this._yscale -= (this._yscale-100)/6;
  180. //if (this._xscale<100) {
  181. // delete this.onEnterFrame;
  182. //}
  183. this.gotoAndPlay(2);
  184. };
  185. quantou._visible = false;
  186. normal_hand._visible = false;
  187. Mouse.show();
  188. onMouseMove = function () {
  189. normal_hand._x = _xmouse;
  190. normal_hand._y = _ymouse;
  191. quantou._x = _xmouse;
  192. quantou._y = _ymouse;
  193. };
  194. if(current<=13||current==25||current==24||current==28||current==30||current==31)//1-13 24 25 28 30 31
  195. getURL("http://e.51somabs.com:8080/WebPage/CourseType.aspx?info="+current,"_bank");
  196. //getURL("WebPage/CourseType.aspx?info="+current,"_bank");
  197.  
  198. //getURL("javascript:window.open('CourseType.aspx?info="+current+"')");
  199.  
  200. };
  201.  
  202. //元件移入事件
  203. this["pic"+d+"_mc"].onRollOver = function() {
  204. normal_hand._visible = false;
  205. quantou._visible = false;
  206. //加载外部图片
  207. //this.loadMovie("beidouxing_light.png");
  208. onMouseMove = function () {
  209. normal_hand._x = _xmouse;
  210. normal_hand._y = _ymouse;
  211. quantou._x = _xmouse;
  212. quantou._y = _ymouse;
  213. };
  214. this.onEnterFrame = function() {
  215. //this._xscale -= (this._xscale-100)/6;
  216. //this._yscale -= (this._yscale-100)/6;
  217. //if (this._xscale<100) {
  218. // delete this.onEnterFrame;
  219. //}
  220. this.gotoAndPlay(2);
  221. };
  222. Mouse.show();
  223. };
  224. //元件移出事件
  225. this["pic"+d+"_mc"].onRollOut = function() {
  226. normal_hand._visible = true;
  227. onMouseMove = function () {
  228. normal_hand._x = _xmouse;
  229. normal_hand._y = _ymouse;
  230. quantou._x = _xmouse;
  231. quantou._y = _ymouse;
  232. };
  233. this.onEnterFrame = function() {
  234. this.gotoAndPlay(1);
  235. };
  236. Mouse.hide();
  237. };
  238. //按下元件移出
  239. this["pic"+d+"_mc"].onReleaseOutside =function()
  240. {
  241. normal_hand._visible = true;
  242. onMouseMove = function () {
  243. normal_hand._x = _xmouse;
  244. normal_hand._y = _ymouse;
  245. quantou._x = _xmouse;
  246. quantou._y = _ymouse;
  247. };
  248. this.onEnterFrame = function() {
  249. //this._xscale -= (this._xscale-100)/6;
  250. //this._yscale -= (this._yscale-100)/6;
  251. //if (this._xscale<100) {
  252. // delete this.onEnterFrame;
  253. //}
  254. this.gotoAndPlay(1);
  255. }
  256. }
  257.  
  258. }
  259. //方向键移出
  260. button_mc.onRollOut = function() {
  261. Mouse.hide();
  262. normal_hand._visible = true;
  263. onMouseMove = function () {
  264. normal_hand._x = _xmouse;
  265. normal_hand._y = _ymouse;
  266. quantou._x = _xmouse;
  267. quantou._y = _ymouse;
  268. };
  269. quantou._visible = false;
  270. };
  271. //btn键入
  272. huakuai.onPress=huakuai.onRollOver=quanping.onPress=quanping.onRollOver=
  273. btnSubstract.onPress=btnSubstract.onRelease=btnSubstract.onRollOver=
  274. btnadd.onPress=btnadd.onRelease=btnadd.onRollOver=
  275. btnadd.onPress=btnadd.onRelease=btnadd.onRollOver=
  276. btn_down.onPress=btn_down.onRelease=btn_down.onRollOver=
  277. btn_left.onPress=btn_left.onRelease=btn_left.onRollOver=
  278. btn_right.onPress=btn_right.onRelease=btn_right.onRollOver=
  279. btn_up.onRelease=btn_up.onRollOver=function(){
  280. Mouse.show();
  281. //this.useHandCursor=false;
  282. normal_hand._visible=false;
  283. onMouseMove = function(){
  284. normal_hand._x = _xmouse;
  285. normal_hand._y = _ymouse;
  286. quantou._x = _xmouse;
  287. quantou._y = _ymouse;
  288.  
  289. };
  290. quantou._visible=false;
  291. };
  292. //Dragmodel状态
  293. UDLR.onPress=UDLR.onRelease=UDLR.onRollOver=dragModel.onPress=dragModel.onRelease=dragModel.onRollOver=function(){
  294. Mouse.show();
  295. this.useHandCursor=false;
  296. normal_hand._visible=false;
  297. onMouseMove = function(){
  298. normal_hand._x = _xmouse;
  299. normal_hand._y = _ymouse;
  300. quantou._x = _xmouse;
  301. quantou._y = _ymouse;
  302. };
  303. }
  304. //移出方向和dragModel鼠标状态
  305. UDLR.onRollOut=dragModel.onRollOut=function(){
  306. Mouse.hide();
  307. normal_hand._visible=true;
  308. onMouseMove = function(){
  309. normal_hand._x = _xmouse;
  310. normal_hand._y = _ymouse;
  311. quantou._x = _xmouse;
  312. quantou._y = _ymouse;
  313. };
  314. }
  315.  
  316. //向上
  317. btn_up.onPress=function(){
  318. var count:Number=0;
  319. _root.onEnterFrame=function(){
  320. //下移动超出
  321. if(souma._y<0&&count<15)
  322. {
  323. var Move:Number=10;//移动距离
  324. var Dvalue:Number=souma._y*-1;//距离最大移动量的距离差
  325. if(Dvalue>Move)
  326. {
  327. souma._y+=Move;
  328. yun1._y+=Move;
  329. yun2._y+=Move;
  330. pubu._y+=Move;
  331. for (var i:Number = 1; i<=31; i++) {
  332. _root["pic"+i+"_mc"]._y +=Move;
  333. }
  334. }
  335. else
  336. {
  337. souma._y+=Dvalue;
  338. yun1._y+=Dvalue;
  339. yun2._y+=Dvalue;
  340. pubu._y+=Dvalue;
  341. for (var i:Number = 1; i<=31; i++) {
  342. _root["pic"+i+"_mc"]._y +=Dvalue;
  343. }
  344. delete _root.onEnterFrame;
  345. }
  346. count++;
  347. }
  348. }
  349. };
  350.  
  351. //向下
  352. btn_down.onPress=function(){
  353. var count:Number=0;
  354. _root.onEnterFrame=function(){
  355. //上移动超出
  356. if(souma._y>(souma._height - Stage.height)*-1&&count<15)
  357. {
  358. var Move:Number=10;//移动距离
  359. var Dvalue:Number=souma._y-((souma._height - Stage.height)*-1);//距离最大移动量的距离差
  360. if(Dvalue>Move)
  361. {
  362. souma._y-=Move;
  363. yun1._y-=Move;
  364. yun2._y-=Move;
  365. pubu._y-=Move;
  366. for (var i:Number = 1; i<=31; i++) {
  367. _root["pic"+i+"_mc"]._y -=Move;
  368. }
  369. }
  370. else
  371. {
  372. souma._y-=Dvalue;
  373. yun1._y-=Dvalue;
  374. yun2._y-=Dvalue;
  375. pubu._y-=Dvalue;
  376. for (var i:Number = 1; i<=31; i++) {
  377. _root["pic"+i+"_mc"]._y -=Dvalue;
  378. }
  379. delete _root.onEnterFrame;
  380. }
  381. count++;
  382. }
  383. }
  384.  
  385. };
  386. //向左
  387. btn_left.onPress=function(){
  388. var count:Number=0;
  389. _root.onEnterFrame=function(){
  390. //右移动超出
  391. if(souma._x<0&&count<20)
  392. {
  393. var Move:Number=10;//移动距离
  394. var Dvalue:Number=souma._x*-1;//距离最大移动量的距离差
  395. if(Dvalue>Move)
  396. {
  397. souma._x+=Move;
  398. yun1._x+=Move;
  399. yun2._x+=Move;
  400. pubu._x+=Move;
  401. for (var i:Number = 1; i<=31; i++) {
  402. _root["pic"+i+"_mc"]._x +=Move;
  403. }
  404. }
  405. else
  406. {
  407. souma._x+=Dvalue;
  408. yun1._x+=Dvalue;
  409. yun2._x+=Dvalue;
  410. pubu._x+=Dvalue;
  411. for (var i:Number = 1; i<=31; i++) {
  412. _root["pic"+i+"_mc"]._x +=Dvalue;
  413. }
  414. delete _root.onEnterFrame;
  415. }
  416. count++;
  417. }
  418. }
  419. };
  420. //向右
  421. btn_right.onPress=function(){
  422. var count:Number=0;
  423. _root.onEnterFrame=function(){
  424. //左移动超出
  425. if(souma._x>(souma._width - Stage.width)*-1&&count<20)
  426. {
  427. var Move:Number=10;//移动距离
  428. var Dvalue:Number=souma._x-((souma._width - Stage.width)*-1);//距离最大移动量的距离差
  429. if(Dvalue>Move)
  430. {
  431. souma._x-=Move;
  432. yun1._x-=Move;
  433. yun2._x-=Move;
  434. pubu._x-=Move;
  435. for (var i:Number = 1; i<=31; i++) {
  436. _root["pic"+i+"_mc"]._x -=Move;
  437. }
  438. }
  439. else
  440. {
  441. souma._x-=Dvalue;
  442. yun1._x-=Dvalue;
  443. yun2._x-=Dvalue;
  444. pubu._x-=Dvalue;
  445. for (var i:Number = 1; i<=31; i++) {
  446. _root["pic"+i+"_mc"]._x -=Dvalue;
  447. }
  448. delete _root.onEnterFrame;
  449. }
  450. count++;
  451. }
  452. }
  453. };
  454.  
  455. //鼠标滚轮事件
  456. Mouse.addListener(this);
  457. //确定最大最小缩放比例
  458. var scale_max:Number=100;
  459. var scale_min:Number=55;
  460. //进行放大缩小前鼠标位置
  461. var tempX:Number;
  462. var tempY:Number;
  463. //移动前各品牌位置差
  464. var MCMoveX:Array = new Array();
  465. var MCMoveY:Array = new Array();
  466. for (var d:Number = 1; d<=31; d++) {
  467. //移动前各个品牌位置差
  468. MCMoveX[d]=_root["pic"+d+"_mc"]._x - _root["souma"]._x;
  469. MCMoveY[d]=_root["pic"+d+"_mc"]._y - _root["souma"]._y;
  470. }
  471. //云未移动前位置
  472. var yunMove1x:Number=yun1._x - _root["souma"]._x;
  473. var yunMove1y:Number=yun1._y - _root["souma"]._y;
  474. var yunMove2x:Number=yun2._x - _root["souma"]._x;
  475. var yunMove2y:Number=yun2._y - _root["souma"]._y;
  476. //瀑布未移动前位置
  477. var pubuMovex:Number=pubu._x -_root["souma"]._x;
  478. var pubuMovey:Number=pubu._y -_root["souma"]._y;
  479. //触发事件
  480. onMouseWheel=function(delta){
  481. //获取缩放前鼠标位置
  482. tempX=souma._xmouse;
  483. tempY=souma._ymouse;
  484.  
  485. var sca:Number = _root["souma"]._xscale + (delta > 0?15: -15);
  486. _root["huakuai"]._y += (delta > 0?-34: 34);
  487. if (sca > scale_max)
  488. {sca = scale_max;
  489. _root["huakuai"]._y=_root["btnadd"]._y+PlusD;}
  490. if (sca < scale_min)
  491. {sca = scale_min;
  492. _root["huakuai"]._y=_root["btnSubstract"]._y-SubtrD;}//最大位置需Y轴平移96
  493. //定位滑块一、最大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
  494. //缩放地图
  495. _root["souma"]._xscale = _root["souma"]._yscale =sca;
  496. //根据鼠标的位置比例 和 地图的当前尺寸 重新定义地图的坐标
  497. _root["souma"]._x=_root._xmouse-tempX * souma._xscale/100;
  498. _root["souma"]._y=_root._ymouse-tempY * souma._yscale/100;
  499. //超出拖动范围
  500. if(souma._x<(souma._width - Stage.width)*-1)
  501. souma._x=(souma._width - Stage.width)*-1;
  502. if(souma._y<(souma._height - Stage.height)*-1)
  503. souma._y=(souma._height - Stage.height)*-1;
  504. if(souma._x>0)
  505. souma._x=0;
  506. if(souma._y>0)
  507. souma._y=0;
  508. //清除拖动EnterFrame
  509. delete souma.onEnterFrame;
  510. //云同比缩放
  511. pubu._xscale=pubu._yscale=yun1._xscale=yun1._yscale=yun2._xscale=yun2._yscale=sca;
  512. yun1._x=_root["souma"]._x + ( yunMove1x * _root["souma"]._xscale /100 );
  513. yun1._y=_root["souma"]._y + ( yunMove1y * _root["souma"]._yscale /100 );
  514. yun2._x=_root["souma"]._x + ( yunMove2x * _root["souma"]._xscale /100 );
  515. yun2._y=_root["souma"]._y + ( yunMove2y * _root["souma"]._yscale /100 );
  516. //瀑布同比缩放
  517. pubu._x=_root["souma"]._x + ( pubuMovex * _root["souma"]._xscale /100 );
  518. pubu._y=_root["souma"]._y + ( pubuMovey * _root["souma"]._yscale /100 );
  519. //品牌同比缩放
  520. for (var mc:Number = 1; mc<=31; mc++) {
  521. _root["pic"+mc+"_mc"]._xscale=_root["pic"+mc+"_mc"]._yscale=sca;
  522. _root["pic"+mc+"_mc"]._x =_root["souma"]._x + ( MCMoveX[mc] * _root["souma"]._xscale /100 );
  523. _root["pic"+mc+"_mc"]._y =_root["souma"]._y + ( MCMoveY[mc] * _root["souma"]._yscale /100 );
  524. }
  525. }
  526.  
  527. //按键实现放大缩小
  528. //缩放
  529. btnSubstract.onPress=function(){
  530. this.onEnterFrame=function(){this.gotoAndPlay(2);}
  531. _root["huakuai"]._y+=(_root["btnSubstract"]._y-_root["huakuai"]._y>SubtrD?34:0);//在滑块距离减号距离大于最小比例位置时自增32
  532. //获取缩放前鼠标位置
  533. tempX=souma._xmouse;
  534. tempY=souma._ymouse;
  535. var sca:Number = _root["souma"]._xscale -15;
  536. if (sca > scale_max)
  537. {sca = scale_max;
  538. _root["huakuai"]._y=_root["btnadd"]._y+PlusD;}
  539. if (sca < scale_min)
  540. {sca = scale_min;
  541. _root["huakuai"]._y=_root["btnSubstract"]._y-SubtrD;}//最大位置需Y轴平移96
  542. //缩放地图
  543. souma._yscale=souma._xscale=sca;
  544. //根据鼠标的位置比例 和 地图的当前尺寸 重新定义地图的坐标
  545. _root["souma"]._x=_root._xmouse-tempX * souma._xscale/100;
  546. _root["souma"]._y=_root._ymouse-tempY * souma._yscale/100;
  547. //超出拖动范围
  548. if(souma._x<(souma._width - Stage.width)*-1)
  549. souma._x=(souma._width - Stage.width)*-1;
  550. if(souma._y<(souma._height - Stage.height)*-1)
  551. souma._y=(souma._height - Stage.height)*-1;
  552. if(souma._x>0)
  553. souma._x=0;
  554. if(souma._y>0)
  555. souma._y=0;
  556. //清除拖动EnterFrame
  557. delete souma.onEnterFrame;
  558. //云、瀑布同比缩放
  559. pubu._xscale=pubu._yscale=yun1._xscale=yun1._yscale=yun2._xscale=yun2._yscale=sca;
  560. yun1._x=_root["souma"]._x + ( yunMove1x * _root["souma"]._xscale /100 );
  561. yun1._y=_root["souma"]._y + ( yunMove1y * _root["souma"]._yscale /100 );
  562. yun2._x=_root["souma"]._x + ( yunMove2x * _root["souma"]._xscale /100 );
  563. yun2._y=_root["souma"]._y + ( yunMove2y * _root["souma"]._yscale /100 );
  564. //瀑布同比缩放
  565. pubu._x=_root["souma"]._x + ( pubuMovex * _root["souma"]._xscale /100 );
  566. pubu._y=_root["souma"]._y + ( pubuMovey * _root["souma"]._yscale /100 );
  567. //品牌同比缩放
  568. for (var mc:Number = 1; mc<=31; mc++) {
  569. _root["pic"+mc+"_mc"]._xscale=_root["pic"+mc+"_mc"]._yscale=sca;
  570. _root["pic"+mc+"_mc"]._x =_root["souma"]._x + ( MCMoveX[mc] * _root["souma"]._xscale /100 );
  571. _root["pic"+mc+"_mc"]._y =_root["souma"]._y + ( MCMoveY[mc] * _root["souma"]._yscale /100 );
  572. }
  573. }
  574. //放大
  575. btnadd.onPress=function(){
  576. this.onEnterFrame=function(){this.gotoAndPlay(2);}
  577. _root["huakuai"]._y -=(_root["huakuai"]._y-root["btnadd"]._y<PlusD?0:34);
  578. //获取缩放前鼠标位置
  579. tempX=souma._xmouse;
  580. tempY=souma._ymouse;
  581. var sca:Number = _root["souma"]._xscale +15;
  582. if (sca > scale_max)
  583. {sca = scale_max;
  584. _root["huakuai"]._y=_root["btnadd"]._y+PlusD;}
  585. if (sca < scale_min)
  586. {sca = scale_min;
  587. _root["huakuai"]._y=_root["btnSubstract"]._y-SubtrD;}//最大位置需Y轴平移96
  588. //缩放地图
  589. souma._yscale=souma._xscale=sca;
  590. //根据鼠标的位置比例 和 地图的当前尺寸 重新定义地图的坐标
  591. _root["souma"]._x=_root._xmouse-tempX * souma._xscale/100;
  592. _root["souma"]._y=_root._ymouse-tempY * souma._yscale/100;
  593. //超出拖动范围
  594. if(souma._x<(souma._width - Stage.width)*-1)
  595. souma._x=(souma._width - Stage.width)*-1;
  596. if(souma._y<(souma._height - Stage.height)*-1)
  597. souma._y=(souma._height - Stage.height)*-1;
  598. if(souma._x>0)
  599. souma._x=0;
  600. if(souma._y>0)
  601. souma._y=0;
  602. //清除拖动EnterFrame
  603. delete souma.onEnterFrame;
  604. //云、瀑布同比缩放
  605. pubu._xscale=pubu._yscale=yun1._xscale=yun1._yscale=yun2._xscale=yun2._yscale=sca;
  606. yun1._x=_root["souma"]._x + ( yunMove1x * _root["souma"]._xscale /100 );
  607. yun1._y=_root["souma"]._y + ( yunMove1y * _root["souma"]._yscale /100 );
  608. yun2._x=_root["souma"]._x + ( yunMove2x * _root["souma"]._xscale /100 );
  609. yun2._y=_root["souma"]._y + ( yunMove2y * _root["souma"]._yscale /100 );
  610. //瀑布同比缩放
  611. pubu._x=_root["souma"]._x + ( pubuMovex * _root["souma"]._xscale /100 );
  612. pubu._y=_root["souma"]._y + ( pubuMovey * _root["souma"]._yscale /100 );
  613. //品牌同比缩放
  614. for (var mc:Number = 1; mc<=31; mc++) {
  615. _root["pic"+mc+"_mc"]._xscale=_root["pic"+mc+"_mc"]._yscale=sca;
  616. _root["pic"+mc+"_mc"]._x =_root["souma"]._x + ( MCMoveX[mc] * _root["souma"]._xscale /100 );
  617. _root["pic"+mc+"_mc"]._y =_root["souma"]._y + ( MCMoveY[mc] * _root["souma"]._yscale /100 );
  618. }
  619. }
  620.  
  621. //滑块拖动事件
  622. huakuai.onPress=function (){
  623. //定位滑块一、最大1位置904.2,201.2】二、最大1位置904.2,232.2】三、最大1位置904.2,270.2】四、最大1位置904.2,298.2
  624. //huakuai.startDrag(false,905,200,905,300);
  625. huakuai.startDrag(false,Stage.width-126.8+70,_root["btnadd"]._y+PlusD ,Stage.width-126.8+70,_root["btnadd"]._y+PlusD+103);
  626. }
  627. //滑块移动
  628. var pointHK:Number;//滑块y坐标
  629. //舞台鼠标弹起事件
  630. someListener.onMouseUp = huakuai.onRelease=function(){
  631. huakuai.stopDrag();
  632. Mouse.show();
  633. normal_hand._visible=false;
  634. onMouseMove = function(){
  635. normal_hand._x = _xmouse;
  636. normal_hand._y = _ymouse;
  637. quantou._x = _xmouse;
  638. quantou._y = _ymouse;
  639. }
  640. pointHK=huakuai._y;
  641. var Point1:Number=Math.abs(pointHK - (_root["btnadd"]._y+PlusD));
  642. var Point2:Number=Math.abs(pointHK - (_root["btnadd"]._y+PlusD+34));
  643. var Point3:Number=Math.abs(pointHK - (_root["btnadd"]._y+PlusD+34+34));
  644. var Point4:Number=Math.abs(pointHK - (_root["btnadd"]._y+34+34+34));
  645. var Point12:Number=(Point1<Point2?Point1:Point2);
  646. var Point34:Number=(Point3<Point4?Point3:Point4);
  647. var PointMin:Number=Point12<Point34?Point12:Point34;
  648. if(PointMin==Point1){
  649. huakuai._y=_root["btnadd"]._y+PlusD;
  650. changeScale(100);
  651. //超出拖动范围
  652. if(souma._x<(souma._width - Stage.width)*-1)
  653. souma._x=(souma._width - Stage.width)*-1;
  654. if(souma._y<(souma._height - Stage.height)*-1)
  655. souma._y=(souma._height - Stage.height)*-1;
  656. if(souma._x>0)
  657. souma._x=0;
  658. if(souma._y>0)
  659. souma._y=0;
  660. }
  661. else if (PointMin==Point2){
  662. huakuai._y=_root["btnadd"]._y+PlusD+34;
  663. changeScale(85);
  664. //超出拖动范围
  665. if(souma._x<(souma._width - Stage.width)*-1)
  666. souma._x=(souma._width - Stage.width)*-1;
  667. if(souma._y<(souma._height - Stage.height)*-1)
  668. souma._y=(souma._height - Stage.height)*-1;
  669. if(souma._x>0)
  670. souma._x=0;
  671. if(souma._y>0)
  672. souma._y=0;
  673. }
  674. else if (PointMin==Point3){
  675. huakuai._y=_root["btnadd"]._y+PlusD+34+34;
  676. changeScale(70);
  677. //超出拖动范围
  678. if(souma._x<(souma._width - Stage.width)*-1)
  679. souma._x=(souma._width - Stage.width)*-1;
  680. if(souma._y<(souma._height - Stage.height)*-1)
  681. souma._y=(souma._height - Stage.height)*-1;
  682. if(souma._x>0)
  683. souma._x=0;
  684. if(souma._y>0)
  685. souma._y=0;
  686. }
  687. else if (PointMin==Point4){
  688. huakuai._y=_root["btnadd"]._y+PlusD+34+34+34;
  689. changeScale(55);
  690. //超出拖动范围
  691. if(souma._x<(souma._width - Stage.width)*-1)
  692. souma._x=(souma._width - Stage.width)*-1;
  693. if(souma._y<(souma._height - Stage.height)*-1)
  694. souma._y=(souma._height - Stage.height)*-1;
  695. if(souma._x>0)
  696. souma._x=0;
  697. if(souma._y>0)
  698. souma._y=0;
  699.  
  700. }
  701. }
  702. //鼠标按下移开滑块,清楚拖动
  703. _root["huakuai"].onReleaseOutside=function(){
  704. _root["huakuai"].stopDrag();
  705. }
  706. //缩放方法
  707. function changeScale(scale:Number){
  708.  
  709. tempX=souma._xmouse;
  710. tempY=souma._ymouse;
  711. var sca:Number = _root["souma"]._xscale =scale;
  712. if (sca > scale_max)
  713. {sca = scale_max;
  714. _root["huakuai"]._y=_root["btnadd"]._y+PlusD;}
  715. if (sca < scale_min)
  716. {sca = scale_min;
  717. _root["huakuai"]._y=_root["btnSubstract"]._y-SubtrD;}//最大位置需Y轴平移96
  718. //缩放地图
  719. _root["souma"]._xscale = _root["souma"]._yscale =sca;
  720. //根据鼠标的位置比例 和 地图的当前尺寸 重新定义地图的坐标
  721. _root["souma"]._x=_root._xmouse-tempX * souma._xscale/100;
  722. _root["souma"]._y=_root._ymouse-tempY * souma._yscale/100;
  723. //清除拖动EnterFrame
  724. delete souma.onEnterFrame;
  725. //云、瀑布同比缩放
  726. pubu._xscale=pubu._yscale=yun1._xscale=yun1._yscale=yun2._xscale=yun2._yscale=sca;
  727. yun1._x=_root["souma"]._x + ( yunMove1x * _root["souma"]._xscale /100 );
  728. yun1._y=_root["souma"]._y + ( yunMove1y * _root["souma"]._yscale /100 );
  729. yun2._x=_root["souma"]._x + ( yunMove2x * _root["souma"]._xscale /100 );
  730. yun2._y=_root["souma"]._y + ( yunMove2y * _root["souma"]._yscale /100 );
  731. //瀑布同比缩放
  732. pubu._x=_root["souma"]._x + ( pubuMovex * _root["souma"]._xscale /100 );
  733. pubu._y=_root["souma"]._y + ( pubuMovey * _root["souma"]._yscale /100 );
  734. //品牌同比缩放
  735. for (var mc:Number = 1; mc<=31; mc++) {
  736. _root["pic"+mc+"_mc"]._xscale=_root["pic"+mc+"_mc"]._yscale=sca;
  737. _root["pic"+mc+"_mc"]._x =_root["souma"]._x + ( MCMoveX[mc] * _root["souma"]._xscale /100 );
  738. _root["pic"+mc+"_mc"]._y =_root["souma"]._y + ( MCMoveY[mc] * _root["souma"]._yscale /100 );
  739. }
  740. }
  741. //窗口大小改变
  742. var myListener:Object = new Object();
  743. myListener.onResize = function () {
  744. //onEnterFrame=function(){
  745. //定位鼠标位置
  746. quantou._x = normal_hand._x = _xmouse;
  747. quantou._y =normal_hand._y = _ymouse;
  748. //定位全屏按钮
  749. quanping._x=50;
  750. quanping._y=60;
  751. //提示文字位置18.75,99.1
  752. //QPXS._x=90;
  753. //QPXS._y=25;
  754. //TCQP._x=90;
  755. //TCQP._Y=25;
  756. QPQH._x=90;
  757. QPQH._y=25;
  758. btn_up._x=Stage.width-127.1+70;
  759. //btn_up._y=Stage.height-554.05-20;
  760. btn_right._x=Stage.width-110.25+70;
  761. //btn_right._y=Stage.height-535.7-20;
  762. btn_down._x=Stage.width-128.5+70;
  763. //btn_down._y=Stage.height-518-20;
  764. btn_left._x=Stage.width-145.35+70;
  765. //btn_left._y=Stage.height-536.85-20;
  766. UDLR._x=Stage.width-127.8+70;
  767. //UDLR._y=Stage.height-535.7-20;
  768. dragModel._x=Stage.width-126.45+70;
  769. //dragModel._y=Stage.height-426.95-20;
  770. btnSubstract._x=Stage.width-126.6+70;
  771. //btnSubstract._y=Stage.height-360.9-20;
  772. btnadd._x=Stage.width-126.65+70;
  773. //btnadd._y=Stage.height-490.55-20;
  774. huakuai._x=Stage.width-126.8+70;
  775. //switch(souma._xscale)
  776. //{
  777. // case 100:
  778. // //huakuai._y=Stage.height-474.8-20;
  779. // //huakuai._y=huakuai._y;
  780. // break;
  781. // case 85:
  782. // //huakuai._y=Stage.height-474.8-20+32;
  783. // //huakuai._y+=32;
  784. // break;
  785. // case 70:
  786. // //huakuai._y=Stage.height-474.8-20+32+32;
  787. // //huakuai._y+=64;
  788. // break;
  789. // case 55:
  790. // //huakuai._y=Stage.height-474.8-20+32+32+32;
  791. // //huakuai._y+=96;
  792. // break;
  793. // }
  794. //超出拖动范围
  795. if(souma._x<(souma._width - Stage.width)*-1)
  796. souma._x=(souma._width - Stage.width)*-1;
  797. if(souma._y<(souma._height - Stage.height)*-1)
  798. souma._y=(souma._height - Stage.height)*-1;
  799. if(souma._x>0)
  800. souma._x=0;
  801. if(souma._y>0)
  802. souma._y=0;
  803.  
  804. //}
  805.  
  806. }
  807. Stage.addListener(myListener);
  808. myListener.onResize();
  809. //quanping._alpha=50;
  810. //添加全屏按钮事件
  811. quanping.onPress=quanping.onRollOver=function(){
  812. normal_hand._visible=false;
  813. Mouse.show();
  814. quantou._x = normal_hand._x = _xmouse;
  815. quantou._y =normal_hand._y = _ymouse;
  816. //onEnterFrame=function(){
  817. // if(quanping._alpha<100){
  818. // quanping._alpha+=5;}
  819. // else
  820. // delete this.onEnterFrame;
  821. // }
  822. }
  823. quanping.onRollOut=function(){
  824. Mouse.hide();
  825. quantou._x = normal_hand._x = _xmouse;
  826. quantou._y =normal_hand._y = _ymouse;
  827. normal_hand._visible=true;
  828. //onEnterFrame=function(){
  829. // if(quanping._alpha>50){
  830. // quanping._alpha-=5;
  831. // }
  832. // else
  833. // delete this.onEnterFrame;
  834. // }
  835. }
  836. quanping.onRelease =function(){
  837. Stage["displayState"] = Stage["displayState"] == "normal" ? "fullScreen" : "normal";
  838. if(Stage["displayState"] == "normal"){
  839. //Mouse.show();normal_hand._visible=false;QPXS._visible=true;TCQP._visible=false;
  840. }
  841. else{
  842. MA._visible=false;
  843. //QPXS._visible=false;TCQP._visible=true;Mouse.hide();
  844. }
  845. quantou._x = normal_hand._x = _xmouse;
  846. quantou._y =normal_hand._y = _ymouse;
  847.  
  848. };//128.35 233.35
  849.  
  850. //trace(_root["QPXS"]._y+","+_root["QPXS"]._x);
  851. //键盘ESC按下退出全屏
  852. //Key.addListener({onKeyDown:function(){
  853. // if(Key.getCode() == Key.ESCAPE){
  854. // Stage["displayState"] = Stage["displayState"] == "normal" ? "fullScreen" : "normal";
  855. // if(Stage["displayState"] == "fullScreen")
  856. // {
  857. // Stage["displayState"] = "normal";
  858. // QPXS._visible=true;TCQP._visible=false;
  859. // }
  860. // }
  861. // }});

对于一些大的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实现动态地图效果的更多相关文章

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

            经过近两年的不懈努力,笔者的原创教程"ActionScript3游戏中的图像编程"最终在今日划上了完美的句号!这其中记录着笔者多年来在游戏制作,尤其是其中图像处理方 ...

  2. AxureRP7.0各类交互效果汇总帖(转)

    了便于大家参考,我把这段时间发布分享的所有关于AxureRP7.0的原型做了整理. 以下资源均有对应的RP源文件可以下载. 当然 ,其中有部分是需要通过完成解密游戏[攻略]才能得到下载地址或者下载密码 ...

  3. css3.0新属性效果在ie下的解决方案(兼容性)

    css3.0增加的新属性,如投影.渐变.旋转.圆角等等!这些新标准属性在ie6.ie7.ie8浏览器版本里得不到很好的支持,相信ie以后的新版本也会支持这些新属性的.目前ie6.ie7.ie8浏览器不 ...

  4. 【转】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/ ...

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

    在上一篇文章中,我们介绍了怎么使用DrawerLayout来实现一个简单的侧拉菜单(使用DrawerLayout实现侧拉菜单),也就是我们常说的抽屉效果,GitHub上类似效果的实现方式非常多,实现出 ...

  6. 【ActionScript】ActionScript3.0对舞台组件的增删改查

    以一个样例来说明ActionScript3.0对舞台组件的增删改查 例如以下图: 在Flash执行的时候,通过脚本.斜向下生成text0-text9十个文本节点. 提供两个功能. 1.在右上角,用户输 ...

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

    Adobe官方并没有"泛型数组"的叫法,这是我自己对Vector的叫法(有点标题党),不过Vector在使用上确实跟c#中的泛型数组有些相似之处. 原作者:菩提树下的杨过出处:ht ...

  8. Vue.2.0.5-过渡效果

    概述 Vue 在插入.更新或者移除 DOM 时,提供多种不同方式的应用过渡效果.包括以下工具: 在 CSS 过渡和动画中自动应用 class 可以配合使用第三方 CSS 动画库,如 Animate.c ...

  9. [ActionScript 3.0] AS3.0 水面波纹效果

    import flash.geom.Point; import flash.display.BitmapData; import flash.filters.DisplacementMapFilter ...

随机推荐

  1. PAT-7-14 电话聊天狂人

    ps: 真不明白为什么水题不能一次ac 7-14 电话聊天狂人(25 分) 给定大量手机用户通话记录,找出其中通话次数最多的聊天狂人. 输入格式: 输入首先给出正整数N(≤10​5​​),为通话记录条 ...

  2. tomcat服务器安装方法

    tomcat: 链接:https://pan.baidu.com/s/1pMEu0hP 密码:g0ah      (tomcat7) jdk :链接:https://pan.baidu.com/s/1 ...

  3. mysql设置更改root密码、mysql服务器的连接、mysql常用命令

     1.设置更改root密码 查看mysql 启动与否,若没启动就运行:/usr/local/mysql56/bin/mysqlps aux |grep mysql  或 netstat -tulnp ...

  4. 重写ajax方法实现请求session过期时跳转登录页面

    jQuery(function($){ var _ajax=$.ajax; // 备份jquery的ajax方法 $.ajax=function(opt){ var _success = opt &a ...

  5. url中携带中文乱码问题

    1.问题描述 在项目中碰见url中经常传递中文参数时,容易出现乱码问题,现在就这个问题产生原因和解决的措施大概分析一下,希望过路人和我能引以为戒. 2.问题分析 由于我们利用URL传递参数这种方式是依 ...

  6. 【HAOI2008】圆上的整点

    数学题 原题:平面上有一个圆, 圆心坐标为(0,0),半径为n. 问圆周上有多少个整点. 整点的定义即x,y坐标均为整数的点. 这根本就是一道数学题,注意是数学题,不是数论,数学! 纯粹就看魔性变公式 ...

  7. 如何将centos7作为DNS服务器

    简单来说,dns服务器是起到缓存的作用.比如说我们第一次dig www.baidu.com的时候,dns服务器因为没有解析过百度地址,所以它需要向上一级dns服务器进行查询,然后查询结果会缓存在这台d ...

  8. Nginx配置基于ip的虚拟主机

    我是在centos7虚拟机上进行实验的 该实验基于添加好ip的基础上,如何给网卡添加ip请查阅我的博客 先来看一下我的ip [root@localhost nginx]# ifconfig ens33 ...

  9. 02c语言指针基础

    & 用来取一个变量的地址 * 用来取一个地址的值 例如: (1)&n 获取n的地址 int *p=&n; *p就等于p的值 (2) 假设 int n=10; *(&n) ...

  10. xcrun: error: invalid active developer path

    问题 mac升级到10.12(macOS Sierra),执行命令,出现如下错误: xcrun: error: invalid active developer path (/Library/Deve ...