资源描述:
《FLASH as3.0常用代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、FLASHas3.0常用代码1.按钮事件(新版)步骤:实现第一帧暂停:右击第一帧,点动作,写代码stop();实现点按钮开始:放一个按钮(可以在窗口菜单->公用库->按钮里找一个)在第一帧的舞台上,属性面板里给按钮取名:实例名称bt1,右击第一帧,点动作,写代码:bt1.addEventListener(MouseEvent.CLICK,f1);functionf1(evt:MouseEvent){gotoAndPlay(2);}////////////////////////// 补充:as2(老版)中的按钮事件 实现第一帧暂停:右击第一帧,点动作,写
2、代码stop(); 实现点按钮开始:放一个按钮(可以在窗口菜单->公用库->按钮里找一个)在第一帧的舞台上,右击按钮,点动作, 写代码: on(release) { gotoAndPlay(2); } //////////////////////////2.按钮超链接linkButton.addEventListener(MouseEvent.CLICK,gotoAdobeSite);functiongotoAdobeSite(event:MouseEvent):void{varadobeURL:URLRequest=newURLRequ
3、est("http://www.baidu.com/");navigateToURL(adobeURL);}3.随机数 Math.random()输出时间vartime1:Date=newDate(); 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(vari:int=0;i<100;i++){g
4、raphics.lineTo(Math.random()*600,Math.random()*400);}5.画三角形varm1: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,10
5、0);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.复制影片剪辑//影片剪辑_属性_高级_类名:snowvarmc:MovieClip=newsnow();addChild(mc);mc.x=300*Math.random();mc
6、.y=200*Math.random();8.变量定义,赋值varn1:Number=9;n1=n1+2;vars1:String=n1.toString(); 9.输入文本//密码框,按钮,输出框stop();bt1.addEventListener(MouseEvent.CLICK,f1);functionf1(evt:MouseEvent){vars1:String;s1="2";if( String(a.text)==s1 ){ b.text="right";}else{ b.text="wrong";}}10.数学运算functionf1(evt:MouseE
7、vent){varstr:String=String(aa.text);varn:Number=10;n=Number(str)+1;bb.text=String(n);}11.不同的帧传递文本//第一帧stop();vars1:String;s1="abc";bt1.addEventListener(MouseEvent.CLICK,f1);functionf1(evt:MouseEvent){s1=this.a.text;gotoAndPlay(2);}//第二帧this.b.text=s1;stop();12