初识AS3(十九)——课件首页代码

[知识点]
1、全屏与帧速设置stage.displayState="fullScreen";stage.frameRate=24;
2、右键设置ContextMenu
3、新增画线工具,在指定范围内画线graphics.moveTo(),graphics.lineTo()
4、 按钮文字说明跟踪 鼠标缓冲移动Tween
5、新增倒计时Timer
6、新增背景音乐音量控制soundTransform
[ 效果]
index0.swf
[代码]

  1. //舞台设置
  2. stage.displayState="fullScreen";
  3. stage.frameRate=24;
  4. //右键设置
  5. var myContextMenu:ContextMenu = new ContextMenu();
  6. removeDefaultItems();
  7. addCustomMenuItems();
  8. this.contextMenu = myContextMenu;
  9. function removeDefaultItems():void {
  10. myContextMenu.hideBuiltInItems();
  11. var defaultItems:ContextMenuBuiltInItems = myContextMenu.builtInItems;
  12. }
  13. function addCustomMenuItems():void {
  14. var zuozhe:ContextMenuItem = new ContextMenuItem("制作:刘常");
  15. myContextMenu.customItems.push(zuozhe);
  16. var wangzhi:ContextMenuItem = new ContextMenuItem("琴者工作室qzgzs.51.net",true);
  17. myContextMenu.customItems.push(wangzhi);
  18. var emaile:ContextMenuItem = new ContextMenuItem("邮箱liu888chang@126.com",true);
  19. myContextMenu.customItems.push(emaile);
  20. var dizhi:ContextMenuItem = new ContextMenuItem("湖北省荆州市公安县埠河中学",true);
  21. myContextMenu.customItems.push(dizhi);
  22. var _close:ContextMenuItem = new ContextMenuItem("关闭",true);
  23. myContextMenu.customItems.push(_close);
  24. wangzhi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, wz);
  25. _close.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, gb);
  26. }
  27. function wz(event:ContextMenuEvent):void {
  28. var url:URLRequest=new URLRequest("http://qzgzs.51.net");
  29. navigateToURL(url,"_blank");
  30. }
  31. function gb(event:ContextMenuEvent):void {
  32. fscommand("quit");
  33. }
  34. //画线
  35. var fw:Sprite = new Sprite(  );
  36. var xian:Sprite = new Sprite( );
  37. addChild(fw);
  38. fw.addChild(xian);
  39. fw.graphics.beginFill(0x000000,0);
  40. fw.graphics.drawRect(0, 30, 800, 540);
  41. fw.graphics.endFill();
  42. fw.addEventListener(MouseEvent.MOUSE_DOWN, ax);
  43. function ax(event:MouseEvent):void {
  44. xian.graphics.lineStyle(4,0xFF0000);
  45. xian.graphics.moveTo(mouseX, mouseY);
  46. fw.addEventListener(MouseEvent.MOUSE_MOVE, yd);
  47. }
  48. stage.addEventListener(MouseEvent.MOUSE_UP, sk);
  49. function sk(event:MouseEvent):void {
  50. fw.removeEventListener(MouseEvent.MOUSE_MOVE, yd);
  51. }
  52. function yd(event:MouseEvent):void {
  53. xian.graphics.lineTo(mouseX, mouseY);
  54. }
  55. //按钮文字说明
  56. var btnname:Array=["最前","最后","后退","播放","音乐","音乐","清除","帮助","教案","退出"];
  57. for (var k:uint=1; k<btnname.length+1; k++) {
  58. this["_btn" + k].addEventListener(MouseEvent.MOUSE_MOVE,btnjg);
  59. this["_btn" + k].addEventListener(MouseEvent.MOUSE_OUT,btnyc);
  60. btn_txt.y=this["_btn" + k].y-18;
  61. btn_txt.visible=false;
  62. }
  63. import fl.transitions.*;
  64. import fl.transitions.easing.*;
  65. var myTween:Tween;
  66. function btnjg(event:MouseEvent):void {
  67. var btn_xh:uint=event.currentTarget.name.split("_btn").join("");
  68. btn_txt.visible=true;
  69. myTween=new Tween(btn_txt,"x", Back.easeOut,btn_txt.x,event.currentTarget.x,0.5,true);
  70. btn_txt.txt.text=btnname[btn_xh-1];
  71. }
  72. function btnyc(event:MouseEvent):void {
  73. btn_txt.visible=false;
  74. myTween.stop();
  75. }

  76. var js:Timer=new Timer(1000,2700);
  77. var swf:Array=["1.swf","2.swf","3.swf","4.swf","5.swf"];
  78. var jishu:uint=0;
  79. var url:URLRequest=new URLRequest(swf[jishu]);
  80. var ldr:Loader=new Loader();
  81. ldr.load(url);
  82. ldr.mask = zezao;
  83. addChild(ldr);
  84. js_mc.js_txt.text="45:00";
  85. //背景音乐控制
  86. var _sound:Sound=new Sound();
  87. var surl:URLRequest=new URLRequest("bjsound.mp3");
  88. var scz:SoundChannel=new SoundChannel();
  89. _sound.load(surl);
  90. scz=_sound.play();
  91. var yl:Number=0.5;
  92. var syl:SoundTransform. = scz.soundTransform;
  93. syl.volume =yl;
  94. scz.soundTransform. =syl;
  95. _btn1.enabled=_btn3.enabled=false;
  96. stage.addEventListener(Event.ENTER_FRAME,gx);
  97. function gx(event:Event):void {
  98. if (jishu==0) {
  99.   _btn5.visible=false;
  100.   _btn6.visible=true;
  101.   _btn1.enabled=_btn3.enabled=false;
  102.   _btn2.enabled=_btn4.enabled=true;
  103.   _btn2.addEventListener(MouseEvent.CLICK,dj2);
  104.   _btn4.addEventListener(MouseEvent.CLICK,dj4);
  105.   _btn1.removeEventListener(MouseEvent.CLICK,dj1);
  106.   _btn3.removeEventListener(MouseEvent.CLICK,dj3);
  107. }
  108. if (jishu==swf.length-1) {
  109.   _btn5.visible=false;
  110.   _btn6.visible=true;
  111.   _btn1.enabled=_btn3.enabled=true;
  112.   _btn2.enabled=_btn4.enabled=false;
  113.   _btn1.addEventListener(MouseEvent.CLICK,dj1);
  114.   _btn3.addEventListener(MouseEvent.CLICK,dj3);
  115.   _btn2.removeEventListener(MouseEvent.CLICK,dj2);
  116.   _btn4.removeEventListener(MouseEvent.CLICK,dj4);
  117. }
  118. if (jishu<(swf.length-1)&&jishu>0) {
  119.   _btn5.visible=true;
  120.   _btn6.visible=false;
  121.   _btn1.enabled=_btn3.enabled=true;
  122.   _btn2.enabled=_btn4.enabled=true;
  123.   _btn1.addEventListener(MouseEvent.CLICK,dj1);
  124.   _btn3.addEventListener(MouseEvent.CLICK,dj3);
  125.   _btn2.addEventListener(MouseEvent.CLICK,dj2);
  126.   _btn4.addEventListener(MouseEvent.CLICK,dj4);
  127.   scz.stop();
  128. }
  129. yl=(ylhk_mc.x-390)/100;
  130. ylt_mc.scaleX=yl;
  131. syl.volume =yl;
  132. scz.soundTransform. =syl;
  133. }
  134. //结尾
  135. function dj2(event:MouseEvent):void {
  136. xian.graphics.clear();
  137. jishu=swf.length-1;
  138. url=new URLRequest(swf[jishu]);
  139. ldr.load(url);
  140. scz.stop();
  141. scz=_sound.play();
  142. }
  143. //向前
  144. function dj4(event:MouseEvent):void {
  145. xian.graphics.clear();
  146. jishu++;
  147. url=new URLRequest(swf[jishu]);
  148. ldr.load(url);
  149. scz.stop();
  150. if (jishu==swf.length-1) {
  151.   scz=_sound.play();
  152. }
  153. }
  154. //开始
  155. function dj1(event:MouseEvent):void {
  156. xian.graphics.clear();
  157. js_mc.js_txt.text="45:00";
  158. jishu=0;
  159. url=new URLRequest(swf[jishu]);
  160. ldr.load(url);
  161. scz.stop();
  162. scz=_sound.play();
  163. js.stop();
  164. js=new Timer(1000,2700);
  165. }
  166. //后退
  167. function dj3(event:MouseEvent):void {
  168. xian.graphics.clear();
  169. jishu--;
  170. url=new URLRequest(swf[jishu]);
  171. ldr.load(url);
  172. scz.stop();
  173. if (jishu==0) {
  174.   scz=_sound.play();
  175.   js.stop();
  176.   js=new Timer(1000,2700);
  177.   js_mc.js_txt.text="45:00";
  178. }
  179. }
  180. //清除线条
  181. _btn7.addEventListener(MouseEvent.CLICK,dj7);
  182. function dj7(event:MouseEvent):void {
  183. xian.graphics.clear();
  184. }
  185. //背景音乐控制及倒计时
  186. var xkls:Sound=new Sound();
  187. var xklsurl:URLRequest=new URLRequest("xkls.mp3");
  188. var xklscz:SoundChannel=new SoundChannel();
  189. xkls.load(xklsurl);
  190. xklscz.stop();
  191. _btn6.addEventListener(MouseEvent.CLICK,dj6);
  192. function dj6(event:MouseEvent):void {
  193. scz.stop();
  194. //倒计时
  195. js.stop();
  196. js=new Timer(1000,2700);
  197. js.addEventListener(TimerEvent.TIMER,djs);
  198. js.addEventListener(TimerEvent.TIMER_COMPLETE,jswc);
  199. js.start();
  200. function djs(event:TimerEvent):void {
  201.   var jss:uint=2700-event.target.currentCount;
  202.   var fen:String=""+int(jss/60);
  203.   var miao:String=""+int(jss`);
  204.   if (fen.length<2) {
  205.    fen="0"+fen;
  206.   }
  207.   if (miao.length<2) {
  208.    miao="0"+miao;
  209.   }
  210.   js_mc.js_txt.text=fen+":"+miao;
  211. }
  212. function jswc(event:TimerEvent):void {
  213.   js.stop();
  214.   js_mc.js_txt.text="END";
  215.   xklscz=xkls.play();
  216. }
  217. }
  218. _btn5.addEventListener(MouseEvent.CLICK,dj5);
  219. function dj5(event:MouseEvent):void {
  220. js_mc.js_txt.text="45:00";
  221. scz.stop();
  222. scz=_sound.play();
  223. js.stop();
  224. js=new Timer(1000,2700);
  225. }
  226. _btn10.addEventListener(MouseEvent.CLICK,tc);
  227. function tc(event:MouseEvent):void {
  228. fscommand("quit");
  229. }
  230. //音量滑块拖动控制
  231. var tdfw:Rectangle=new Rectangle(390,586,100,0);//拖动范围
  232. ylhk_mc.addEventListener(MouseEvent.MOUSE_DOWN,ylhkax);
  233. ylhk_mc.addEventListener(MouseEvent.MOUSE_UP,ylhksk);
  234. ylhk_mc.buttonMode=true;
  235. stage.addEventListener(MouseEvent.MOUSE_UP,ylhksk);
  236. function ylhkax(event:MouseEvent):void {
  237. ylhk_mc.startDrag(false,tdfw);
  238. }
  239. function ylhksk(event:MouseEvent):void {
  240. ylhk_mc.stopDrag();
  241. }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值