FLASH_as3.0常用代码.doc_第1页
FLASH_as3.0常用代码.doc_第2页
FLASH_as3.0常用代码.doc_第3页
FLASH_as3.0常用代码.doc_第4页
FLASH_as3.0常用代码.doc_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

FLASH as3.0常用代码1.按钮事件(新版)步骤:实现第一帧暂停:右击第一帧,点动作,写代码 stop();实现点按钮开始:放一个按钮(可以在窗口菜单-公用库-按钮里找一个)在第一帧的舞台上,属性面板里给按钮取名:实例名称 bt1 ,右击第一帧,点动作,写代码:bt1.addEventListener(MouseEvent.CLICK ,f1);function f1(evt:MouseEvent) gotoAndPlay(2); / 补充:as2(老版)中的按钮事件 实现第一帧暂停:右击第一帧,点动作,写代码 stop(); 实现点按钮开始:放一个按钮(可以在窗口菜单-公用库-按钮里找一个)在第一帧的舞台上,右击按钮,点动作, 写代码: on (release) gotoAndPlay(2); /2.按钮超链接linkButton.addEventListener(MouseEvent.CLICK, gotoAdobeSite); function gotoAdobeSite(event:MouseEvent):voidvar adobeURL:URLRequest = new URLRequest(/);navigateToURL(adobeURL);3.随机数 Math.random ()输出时间 var time1:Date=new Date(); t1.text=time1.toLocaleTimeString(); 4.画线1graphics.lineStyle(3,0xff0000,0.3);graphics.moveTo(300,100);graphics.lineTo(200,300);画线2graphics.lineStyle(1,0xff0000,1);for(var i:int=0;i100;i+)graphics.lineTo(Math.random ()*600,Math.random ()*400);5. 画三角形var m1:MovieClip = new(MovieClip); /声明一个新的mc类bt1,并用new来构造它 m1.graphics.lineStyle(2, 0x990000, .75);/使用bt1的graphics属性设置线条粗细,颜色,透明度m1.graphics.beginFill(0x00FF00);/以下的代码是用graphics画三角形。 m1.graphics.moveTo(100,200); m1.graphics.lineTo(200,100); m1.graphics.lineTo(0,100); m1.graphics.lineTo(100,200); this.addChild(m1);6.影片剪辑属性设置aa.x = aa.x+20;aa.y = aa.y+20;aa.rotation=aa.rotation+10;aa.scaleX=aa.scaleX*1.1;aa.scaleY=aa.scaleY*1.1aa.alpha=0.5;7.复制影片剪辑/影片剪辑_属性_高级_类名:snowvar mc:MovieClip = new snow();addChild(mc);mc.x=300*Math.random ();mc.y=200*Math.random ();8.变量定义,赋值var n1:Number = 9;n1=n1+2;var s1:String = n1.toString();9.输入文本/密码框,按钮,输出框stop();bt1.addEventListener(MouseEvent.CLICK ,f1);function f1(evt:MouseEvent) var s1:String;s1=2;if( String(a.text)=s1 ) b.text=right;else b.text=wrong; 10.数学运算function f1(evt:MouseEvent) var str:String =String( aa.text);var n:Number=10;n=Number(str)+1;bb.text= String(n); 11.不同的帧传递文本/第一帧stop();var s1:String;s1=abc;bt1.addEventListener(MouseEvent.CLICK ,f1);function f1(evt:MouseEvent) s1=this.a.text;gotoAndPlay(2); /第二帧this.b.text=s1;stop();12.数组使用var s:Array = new Array(4); var i;s0=8;s1=4;s2=7;s3=9;a.text=String(s0* s1);13.组件/单选按钮r1,文本框t1,按钮bt1bt1.addEventListener(MouseEvent.CLICK ,f1);function f1(evt:MouseEvent) if(r1.selected=true)t1.text=right;else t1.text=fasle; 14下雨:新键一个影片剪辑。在里面作出来一滴雨落下得效果。然后设置元件属性-链接类 为 snow。在第2,3帧上面插入关键帧。在第一帧动作里面写上var i;i=1;在第2帧上面写上var mc:MovieClip = new snow();if(i50)mc.x=550*Math.random ();mc.y=450*Math.random ();mc.alpha=Math.random ()*1;addChild(mc);i=i+1;第3贞上面写上gotoAndPlay(2);15.声音控制/声音_属性_类名:ccvar song:SoundChannel;var mysound:Sound; mysound=new cc(); var po:Number=0; /开始:song=mysound.play(0); /暂停:bt2.addEventListener(MouseEvent.CLICK ,f2);function f2(evt:MouseEvent) po=song.position;song.stop(); /继续播放:bt3.addEventListener(MouseEvent.CLICK ,f3);function f3(evt:MouseEvent) song=mysound.play( po ); 16.临时输出trace(aa);17.类的定义与对象的声明import s2;var ss:s2 = new s2();var n:Number;n=ss.a ;trace(n);/package public class s2 public var a:Number;public var b:Number;public function s2() this.a=2; this.b=3 public function f (n:Number):Number return 10;/FLASH as2.0常用代码1.暂停: stop();2.按钮开始:on (release) gotoAndPlay(2);3.数组的用法:var s=new Array(4);s0=8s1=4s2=7s3=9for(i=0;is.length;i+)a.text=a.text+ si+,4.鼠标隐藏:_root.m._x=_root._xmouse ;_root.m._y=_root._ymouse ;Mouse.hide ();5.声音的控制代码:myMusic = new Sound();/建立一个名为 myMusic的声音对象 myMusic.attachSound(m1); /将链接标识符为 mySound的音乐捆绑到 myMusic对象上 /on (release) myMusic.start(myMusic.position/1000); /从当前位置开始播放 play(); /on (release)myMusic.stop(); /on (release) myMusic.start(0); play();6.动态文本变量:Flash8用法: b.text= Number(a.text)+1; a,b为实例名称低版本用法: b=Number(a)+1; a,b为变量名称 7.随机数用法:int(Math.random()*1000%30)+1;8.按钮控制对象属性用法:on(release)a1=getProperty(d1,_x)a2=getProperty(d1,_y)a3=getProperty(d1,_rotation)setProperty(d1,_x,a1+20);setProperty(d1,_y,a2+20);setProperty(d1, _rotation,a3+ 45);9.if语句用法:on (release)if(a.text=abc)bb=right;elsebb=false;gotoandplay(2);10下雨:新键一个影片剪辑。在里面作出来一滴雨落下得效果。然后设置实例名称为“CC”然后返回到场景1。在之后就是从库里面把影片剪辑拖到舞台上。在之后在第2,3帧上面插入关键帧。在第一帧动作里面写上var i; i=1;在第2帧上面写上duplicateMovieClip(CC,CC+i,i); m=thisCC+i; m._x=random(550);m._y=random(450); m._alpha=random(80)+20; i=i+1;if(i=50)i=10第3贞上面写上gotoAndPlay(2);11.下雪一帧代码,无需其他操作function addMasker()_root.createEmptyMovieClip(masker, -2);with (masker)lineStyle(1, 13421772, 100);beginFill(0, 100);moveTo(sideDisWidth, sideDisHeight);lineTo(sideDisWidth + sceneWidth, sideDisHeight);lineTo(sideDisWidth + sceneWidth, sideDisHeight + sceneHeight);lineTo(sideDisWidth, sideDisHeight + sceneHeight);endFill(); / End of withcreateSnow(); / End of the functionfunction createSnow()var _l1 = 0;while (_l1 snow._x)snow._x = sideDisWidth + sceneWidth; / end ifif (sideDisWidth + sceneWidth snow._x)snow._x = sideDisWidth; / end ifif (sideDisHeight + sceneHeight =500) this.clear(); this.onEnterFrame = undefined; this.removeMovieClip(); ; ; work_play_caput = function (path) thispath.createEmptyMovieClip(play_caput, 2000); tellTarget (thispathplay_caput) lineStyle(0.25, 0x000000, 100); beginFill(0x000000, 100); moveTo(0, -10); curveTo(-10, -8, -10, 0); curveTo(-8, 10, 0, 10); curveTo(10, 8, 10, 0); curveTo(8, -10, 0, -10); ; work_play1_run = function (x, y, xscale, yscale) this.createEmptyMovieClip(play1_run, 1000); work_play_caput(play1_run); play1_run._xscale = xscale; play1_run._yscale = yscale; play1_run._x = x; play1_run._y = y; tellTarget (play1_run) play_caput._xscale = 65; play_caput._yscale = 65; play_time = 0; this.play1_run.onEnterFrame = function() this.play_time+; tellTarget (this) if (play_time = 1) clear(); play_caput._x = 17; play_caput._y = 5; lineStyle(3, 0x000000, 100); moveTo(15, 10); lineTo(7, 15); lineTo(2, 22); moveTo(15, 10); lineTo(20, 17); lineTo(28, 17); moveTo(15, 10); lineTo(12, 20); lineTo(12, 28); moveTo(12, 28); lineTo(7, 40); lineTo(0, 45); lineTo(3, 48); moveTo(12, 28); lineTo(20, 35); lineTo(15, 40); lineTo(16, 42); else if (play_time = 3) clear(); play_caput._x = 23; play_caput._y = 5; lineStyle(3, 0x000000, 100); moveTo(21, 11); lineTo(10, 14); lineTo(5, 20); moveTo(21, 11); lineTo(27, 18); lineTo(35, 15); moveTo(21, 11); lineTo(18, 20); lineTo(16, 30); moveTo(16, 30); lineTo(10, 35); lineTo(1, 40); lineTo(0, 43); moveTo(16, 30); lineTo(22, 33); lineTo(27, 41); lineTo(30, 43); else if (play_time = 5) clear(); play_caput._x = 25; play_caput._y = 5; lineStyle(3, 0x000000, 100); moveTo(22, 11); lineTo(10, 16); lineTo(8, 24); moveTo(22, 11); lineTo(25, 20); lineTo(32, 18); moveTo(22, 11); lineTo(18, 21); lineTo(18, 30); moveTo(18, 30); lineTo(10, 35); lineTo(2, 35); lineTo(0, 36); moveTo(18, 30); lineTo(22, 36); lineTo(25, 47); lineTo(30, 47); else if (play_time = 7) clear(); play_caput._x = 18; play_caput._y = 6; lineStyle(3, 0x000000, 100); moveTo(15, 11); lineTo(13, 18); lineTo(16, 20); moveTo(15, 11); lineTo(11, 18); lineTo(14, 25); moveTo(15, 11); lineTo(12, 20); lineTo(11, 25); moveTo(11, 25); lineTo(16, 36); lineTo(9, 36); lineTo(10, 38); moveTo(11, 25); lineTo(12, 35); lineTo(10, 45); lineTo(13, 45); else if (play_time = 8) play_time = 0; ; ; work_play2_arise = function () this.createEmptyMovieClip(play2_arise, 2000); work_play_caput(play2_arise); tellTarget (play2_arise) play_caput._x = 2; play_caput._y = -20; lineStyle(4, 0x000000, 100); moveTo(-7, -5); lineTo(6, -7); moveTo(-4, -9); lineTo(5, -3); moveTo(1, -11); lineTo(0, 10); moveTo(0, 10); lineTo(1, 23); lineTo(-3, 35); lineTo(2, 35); moveTo(0, 10); lineTo(-6, 21); lineTo(4, 29); lineTo(1, 33); ; player_run = function () clear(); lineStyle(5, 0x000000, 100); moveTo(sx, sy); lineTo(zs1x, zs1y); lineTo(zs2x, zs2y); moveTo(sx, sy); lineTo(ys1x, ys1y); lineTo(ys2x, ys2y); moveTo(sx, sy); lineTo(st1x, st1y); lineTo(st2x, st2y); moveTo(st2x, st2y); lineTo(zj1x, zj1y); lineTo(zj2x, zj2y); lineTo(zj3x, zj3y); moveTo(st2x, st2y); lineTo(yj1x, yj1y); lineTo(yj2x, yj2y); lineTo(yj3x, yj3y); setProperty(/tou2, _x, toux2); setProperty(/tou2, _y, touy2); lineStyle(5, 0x930093, 100); moveTo(sx2, sy2); lineTo(zs1x2, zs1y2); lineTo(zs2x2, zs2y2); moveTo(sx2, sy2); lineTo(ys1x2, ys1y2); lineTo(ys2x2, ys2y2); moveTo(sx2, sy2); lineTo(st1x2, st1y2); lineTo(st2x2, st2y2); moveTo(st2x2, st2y2); lineTo(zj1x2, zj1y2); lineTo(zj2x2, zj2y2); lineTo(zj3x2, zj3y2); moveTo(st2x2, st2y2); lineTo(yj1x2, yj1y2); lineTo(yj2x2, yj2y2); lineTo(yj3x2, yj3y2); ; /-new_load_data- tree_play_time = 0; tree_NO = 0; play_time = 0; /work_play_caput(); /play_caput._visible = false; /-start_play- trees_play = function () / 每当播放速度值达到15时 复制一棵树 if (tree_play_time = 15) / 随机产生每一棵树的大小及移动的速度 speed_time = int(random(50)+30; / 制造树 work_tree(tree_NO, speed_time); tree_NO+; tree_play_time = 0; tree_play_time+; ; this.onEnterFrame = function() play_time+; /放置人物1跑动 if (play_time = 1) work_play1_run(319, 94, -150, 150); /树移动 trees_play(); ;课件制作一、封面上制作一个按钮an(实例名),按下播放 an01.addEventListener(MouseEvent.CLICK, f1_gotoAndStopframe);function f1_gotoAndStopframe(event:MouseEvent):void play()二、剪辑上放播放 停止按钮 bf tz 剪辑mc import flash.events.MouseEvent;bf.addEventListener(MouseEvent.CLICK, bf);function bf(event:MouseEvent) :voidmc.play()tz.addEventListener(MouseEvent.CLICK, tz);function tz(event:MouseEvent) :voidmc.stop()三、画面上设置上一步 下一步按钮使课件返回或前进 xyb syb syb.addEventListener(MouseEvent.CLICK, fl_ClickToGoToPreviousFrame);function fl_ClickToGoToPreviousFrame(event:MouseEvent):voidprevFrame();/* 单击以转到下一帧并停止单击指定的元件实例会将播放头移动到下一帧并停止此影片。*/xyb.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextFrame);function fl_ClickToGoToNextFrame(event:MouseEvent):voidnextFrame();四、 点击到剪辑的哪一帖放 an mc an.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_m);function fl_ClickToGoToAndStopAtFrame_m(event: MouseEvent): void mc.gotoAndStop(2)五|import flash.events.MouseEvent;/*单击以转到帧并停止单击指定的元件实例会将播放头移动到时间轴中的指定帧并停止影片。可在主时间轴或影片剪辑时间轴上使用。说明:1. 单击元件实例时,用希望播放头移动到的帧编号替换以下代码中的数字 5。*/an5.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_a);function fl_ClickToGoToAndStopAtFrame_a(event: MouseEvent): void sm.play()sm.x = 80;sm.y = 40;sm.scaleX = 0.8sm.scaleY = 0.8ps.alpha = 0;hz.alpha = 0;an7.alpha = 0an8.alpha = 0an5.x = 650.15an5.y = 469.40an6.x = 702.3an6.y = 469.4an6.addEventListener(MouseEvent.CLICK, f1_ClickToGoToAndStopAtFrame_b);function f1_ClickToGoToAndStopAtFrame_b(event: MouseEvent): void sm.stop()sm.x = 30sm.y = 141.55sm.scaleX = sm.scaleY = 0.45ps.alpha = 1hz.alpha = 1an7.alpha = 1an8.alpha = 1an5.x = 290.35an5.y = 364.75an6.x = 342.5an6.y = 364.75an7.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_c);function fl_ClickToGoToAndStopAtFrame_c(event: MouseEvent): void ps.play()ps.x = 80;ps.y = 40;ps.scaleX = 0.8ps.scaleY = 0.8sm.alpha = 0;hz.alpha = 0;an5.alpha = 0an6.alpha = 0an7.x = 650.15an7.y = 469.40an8.x = 702.3an8.y = 469.4an8.ad

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论