




已阅读5页,还剩21页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
二维图形技术复习资料 By BW1.飞机沿轨迹运动import flash.events.MouseEvent;stop();plane.stop();Object(this).Butn.addEventListener(MouseEvent.CLICK,airplanePlay);function airplanePlay(e:MouseEvent)gotoAndPlay(2);plane.play();引导层是轨迹,飞机是被引导层 选中飞机时的样子2.计算两点距离import includes.CPoint;var point1:CPoint=new CPoint(12,30,50);var point2:CPoint=new CPoint(2,3,5);trace(点1的坐标(,point1.xx,point1.yy,point1.zz,);trace(点2的坐标(,point2.xx,point2.yy,point2.zz,);function Distance(p1:CPoint,p2:CPoint):Numbervar xvalue=p1.xx-p2.xx;var yvalue=p1.yy-p2.yy;var zvalue=p1.zz-p2.zz;var dis:Number=Math.sqrt(xvalue*xvalue+yvalue*yvalue+zvalue*zvalue);return dis;var disvalue=Distance(point1,point2);trace(the distance of between p1 and p2 is,disvalue);3.简单数据类型1var num:int=6789 /定义数字var temp:int=num /取得数字的拷贝var a:int=temp/1000 /得到千位数temp=temp-a*1000 /去掉千位var b:int=temp/100 /得到百位数temp=temp-b*100 /去掉百位var c:int=temp/10 /得到十位数temp=temp-c*10 /去掉十位var d:int=temp /得到个位数trace(a,b,c,d)4.简单数据类型2var num:int=6789 /定义数字var str=String(num) /数字转换为字符串var a:int=str.charAt(0) /取得索引0处的字符即6var b:int=str.charAt(1) /取得索引1处的字符即7var c:int=str.charAt(2) /取得索引2处的字符即8var d:int=str.charAt(3) /取得索引3处的字符即9trace(a,b,c,d) /输出数位5.按钮事件import flash.events.MouseEvent;Object(this).left_button.addEventListener(MouseEvent.CLICK,movex);/定义movex函数var speed:int=5;function movex(e:MouseEvent):voidObject(this).car_movieclip.x-=speed;Object(this).right_button.addEventListener(MouseEvent.CLICK,movexright);function movexright(e:MouseEvent) Object(this).car_movieclip.x+=speed;/ trace(Object(this).car_movieclip.x);if(Object(this).car_movieclip.xstage.stageWidth)Object(this).car_movieclip.x=-250;/trace(stage.stageWidth,stage.stageHeight);Object(this).alpha2_button.addEventListener(MouseEvent.CLICK,reducealpha);function reducealpha(e:MouseEvent)if(Object(this).car_movieclip.alpha0)Object(this).car_movieclip.alpha-=0.1;elseObject(this).car_movieclip.alpha=1;Object(this).alpha1_button.addEventListener(MouseEvent.CLICK,addalpha);function addalpha(e:MouseEvent)if(Object(this).car_movieclip.alpha1)Object(this).car_movieclip.alpha+=0.1;Object(this).rotation_button.addEventListener(MouseEvent.CLICK,rotationx);function rotationx(e:MouseEvent)Object(this).car_movieclip.rotationX+=15;Object(this).visible_button.addEventListener(MouseEvent.CLICK,hidemovieclip);function hidemovieclip(e:MouseEvent)if(Object(this).car_movieclip.visible=true)Object(this).car_movieclip.visible=false;elseObject(this).car_movieclip.visible=true; 选中汽车alpha+ 的名字是 alpha1_buttonalpha- 的名字是 alpha2_buttonhide 的名字是 visible_button6.创建影片剪辑类import flash.display.MovieClip;import flash.events.MouseEvent;var i:int;for(i=1;i-Object(this).plane_mc.width)Object(this).plane_mc.x-=speed;else Object(this).plane_mc.x=stage.stageWidth;if(keynumber=KEY_RIGHT)if(Object(this).plane_mc.xy)return x;return y;trace(Max(45,80);function onClick(e:MouseEvent)mc.x+=5;mc.addEventListener(click,onClick);function traceMsg():void trace(this is a function); function refeFunc(f:Function):void f(); refeFunc(traceMsg);var a:int= 1;trace(函数调用前,实参a=+a);test(a);trace(函数调用后,实参a=+a);function test(x):void var y:int;x += 5;trace(调用函数中,形参x=+x);/建立一个对象var person:Object = new Object()/动态创建属性ageperson.age=20;trace(函数调用前,实参person.age=+person.age);test1(person);trace(函数调用后,实参person.age=+person.age);function test1(per:Object):void per.age = 10;/修改对象的age属性trace(函数调用中,形参per.age=+per.age);function test2(y:int,x:int=0):Boolean return xy; trace(test2(20); trace(test2(15,5); /*var speed:int=10;trace(this.speed);*/var speed:Number=5onMove()function onMove()trace(this.speed)/5var speed:Number=6trace(speed)/6trace(this.speed)/5 图层二其实就呢个蓝色的框框,就是mc啦,还是个影片剪辑14.函数定义第一个as: function area(r:*):Number var b:Boolean=r is Number; if(!b) return NaN; return Math.PI*r*r;var a=area(10.5);trace(a);trace(area(7);trace(area(str);第二个as:function btnCon(obj, frameNum) :voidif (this.currentFrame = frameNum) obj.alpha =.5obj.enabled = false; else obj.alpha =1obj.enabled = true;btnCon(backBtn,1);btnCon(forwardBtn,this.totalFrames);蓝色按钮:backBtn褐色按钮: forwardBtn15.绘图函数this.graphics.lineStyle(5)this.graphics.moveTo(250,0)this.graphics.lineTo(350,100)root.graphics.lineStyle(10)root.graphics.moveTo(350,0)root.graphics.lineTo(450,100)/画线var sp1:Shape=new Shape();this.addChild(sp1)drawLine(sp1.graphics)function drawLine(g:Graphics):void with (g) lineStyle(3);moveTo(200,0);curveTo(400,0,300,100);/绘制矩形var sp:Shape=new Shape();this.addChild(sp)drawrect(sp.graphics)function drawrect(g:Graphics):void with (g) beginBitmapFill(new Photo(0,0)drawRect(0,0,187,365)/绘制填充颜色var sp2:Shape=new Shape();this.addChild(sp2);drawrectwithcolor(sp2.graphics);function drawrectwithcolor(g:Graphics):void with (g) beginFill(0xFF5599)drawRect(230,200,200,150)16.按键显示动画键盘输入一大堆乱七八糟的字幕会在屏幕上跳来跳去stage.addEventListener(KeyboardEvent.KEY_DOWN,charpaly);function charpaly(e:KeyboardEvent):voidvar keycode:uint=e.charCode;var str:String=String.fromCharCode(keycode);var txt:TextField=new TextField();txt.text=str;txt.x=Math.random()*550;txt.y=Math.random()*300;txt.addEventListener(Event.ENTER_FRAME,txtmove);this.addChild(txt);function txtmove(e:Event):voidvar txt1:TextField=e.target;txt1.y+=(Math.random()*550-txt1.y)/10;if(txt1.y1)txt1.removeEventListener(Event.ENTER_FRAME,txtmove);this.removeChild(txt1);17.键盘事件+enterframe动画W A S D控制图形上下左右运动const KEY_A:uint=65;const KEY_D:uint=68;const KEY_S:uint=83;const KEY_W:uint=87;var key:Object=new Objectvar speed:Number=2stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDown)stage.addEventListener(KeyboardEvent.KEY_UP,keyUp)this.addEventListener(Event.ENTER_FRAME,test)function isDown(keyCode:uint):Booleanreturn keykeyCode?true:false/按下事件侦听器function keyDown(e:KeyboardEvent):voidkeye.keyCode=true/释放事件侦听器function keyUp(e:KeyboardEvent):voiddelete keye.keyCodefunction test(e:Event):voidMC 也就是那个影片剪辑的圆啦if(keyKEY_A)mc.x-=speedif(keyKEY_D)mc.x+=speedif(keyKEY_W)mc.y-=speedif(keyKEY_S)mc.y+=speed18.海盗射击转动鼠标控制手的方向,单机鼠标发射一个子弹var loop:Timer=new Timer(30);loop.addEventListener(TimerEvent.TIMER,armRotation);loop.start();function armRotation(e:TimerEvent)/var hand:MovieClip=arm;var radian=getRadian(arm.x,arm.y,this.mouseX,this.mouseY);arm.rotation=radian*180/Math.PI;trace(arm.x,arm.y);trace(stage.mouseX,stage.mouseY);/子弹的初始位置var bulletx:Number=arm.x;var bullety:Number=arm.y;/子弹运动速度,相当图8.37中的AB长度var speed:Number=5stage.addEventListener(MouseEvent.CLICK,shoot)function shoot(e:MouseEvent):void/根据鼠标坐标和初始位置计算弧度,相当图8.35中的角BACvar radian:Number=getRadian(bulletx,bullety,this.mouseX,this.mouseY)/从库中创建子弹var bullet:Bullet=new Bullet()/初始化子弹位置bullet.x=bulletx+Math.cos(radian)*arm.width;bullet.y=bullety+Math.sin(radian)*arm.height;/根据余弦函数计算子弹的x速度,相当于计算图8.35中的ACbullet.spdx=Math.cos(radian)*speed/根据正弦函数计算子弹的y速度
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【正版授权】 ISO/IEC 30129:2015/AMD2:2025 EN Amendment 2 - Information technology - Telecommunications bonding networks for buildings and other structures
- 【正版授权】 ISO 18193:2021/Amd 1:2025 EN Cardiovascular implants and artificial organs - Cannulae for extracorporeal circulation - Amendment 1
- 【正版授权】 ISO 18374:2025 EN Dentistry - Artificial intelligence (AI) and augmented intelligence (AuI) based 2D radiograph analysis - Data generation,data annotation and data processi
- 【正版授权】 ISO 10934:2025 EN Microscopes - Vocabulary for light microscopy
- 糖尿病足考试试题及答案
- 官方兽医试题及答案
- 阿里巴巴考试题及答案
- 北京购房专业知识培训课件
- 人行清算面试题及答案
- pte考试题型及答案
- 《电化学原理与应用》课程教学大纲
- 高海拔作业引发的危险
- 甲醇安全知识培训
- (对外)出租车驾驶员安全行车常识培训课件
- 高效时间管理-提升个人工作效率的方案
- 科技特派员服务规范
- 红墩界煤矿矿井水综合利用排水管线建设项目环境影响报告
- 报案材料格式范文范文(通用多篇)
- 函调政审证明材料表范例
- 个人理财第3版课后部分参考答案宋蔚蔚
- 北京口腔专业门急诊病历考核评价实施细则
评论
0/150
提交评论