flash动画代码大全

flash动画代码大全

ID:16681284

大小:55.00 KB

页数:21页

时间:2018-08-23

上传者:U-5097
flash动画代码大全_第1页
flash动画代码大全_第2页
flash动画代码大全_第3页
flash动画代码大全_第4页
flash动画代码大全_第5页
资源描述:

《flash动画代码大全》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

适时时间代码:this.createTextField("my_year",1,100,100,300,100);this.createTextField("my_month",2,200,100,300,100);this.createTextField("my_day",3,300,100,300,100);this.createTextField("my_hours",4,100,150,300,100);this.createTextField("my_minutes",5,200,150,300,100);this.createTextField("my_seconds",6,300,150,300,100);this.onEnterFrame=function(){varmy_date:Date=newDate();my_txt.text=my_date.getSeconds();my_year.text=my_date.getFullYear()+"年";my_month.text=int(int(my_date.getMonth())+1)+"月";my_day.text=my_date.getDate()+"日";my_hours.text=my_date.getHours()+"时";my_minutes.text=my_date.getMinutes()+"分";my_seconds.text=my_date.getSeconds()+"秒";};两个mc相撞问题:我做了两个MC,分别是jj和oo,,oo是一个正方形,jj是一个圆,影片剪辑的动作是on(keyPress""){this._x+=5;}两个影片剪辑同在一帧上,帧上的动作是:_root.onEnterFrame=function(){if(jj.hitTest(oo)){oo._x+=5;}};我想实现的是jj向右移动遇到oo,然后jj推着oo一起移动,类似于以推箱子的小游戏。问题是jj遇到oo后照样跑了,oo动都不动,望指点。判断i能不能被2整除if(i%2==0){otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand d=2//能被2整除}else{d=1;}在某帧上停留一定的时间stop();                              //停止播放影片varfantast=setInterval(go,5000);    //设置每5秒钟调用一次go()函数。functiongo(){                      //自定义函数 play();                             //函数内容,就是继续播放影片。 clearInterval(fantast);            //清除setInterval()轮询}在影片剪辑上写下面代码播放点击时调用库中的另外影片剪辑(这个影片剪辑属性标识符为对应的“h”+n)onClipEvent(load){vari=0;}on(press){++i;varn=random(3);attachMovie("h"+n,"mc"+i,i);this["mc"+i]._x=this._xmouse;this["mc"+i]._y=this._ymouse;this["mc"+i]._rotation=random(5)*120;}随机改变颜色:colorpy1=random(255);colorpy2=random(255);colorpy3=random(255);mycolor=newColor(eval("a"+i));myobject={rb:colorpy1,gb:colorpy2,bb:colorpy3};otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand mycolor.setTransform(myobject);k=Number(wenben3.text)(让输入文本中的文字变成数)this[“a”+i].gotoandPlay(5)mc的大小(height和width)旋转角度(rotation)透明度(alpha)a._visible(可见性)=true(真)或false(假)a=random(10)(随机)mouse.hide()(隐藏鼠标)mc1.setMask(mc2.a)(mc1被mc2中的a层所遮罩)属性:使用运行时位图缓存动作层的命令(快进、快退)kj_btn.onRelease=function(){gotoAndPlay(_root._currentframe+10);};kt_btn.onRelease=function(){gotoAndPlay(_root._currentframe-10);};cjxx_btn.onRelease=function(){nextScene();};cjxs_btn.onRelease=function(){prevScene();};动作按钮让图片变大或变小(a为实例名)on(release){a._yscale=a._yscale*1.1;a._xscale=a._xscale*1.1;}otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand 如果……否则语句(如果帧在1跳到10否则向上一帧)on(release){if(a._currentframe==1){a.gotoAndPlay(10);}else{a.prevFrame();}8、播放器窗口全屏显示on(release){  fscommand("fullscreen",true);}9、取消播放器窗口的全屏on(release){  fscommand("fullscreen",false);}10、播放的画面,随播放器窗口大小的,改变而改变on(release){  fscommand("allowscale",true);}11、播放的画面,不论播放器窗口有多大,都保持原尺寸不变on(release){  fscommand("allowscale",otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand false);}12、打开一个网页,如果该“网页”和“flash动画”在同一个文件夹里:on(release){  getURL("abc.htm");}13、打开一个网页,如果该“网页”是在网络上的其他站点里:on(release){  getURL(http://www.cvso.cn);}播放按钮动作:(隐藏)on(release){play();r_btn._visible=0;p_btn._visible=1;}暂停按钮的动作:(隐藏)on(release){stop();r_btn._visible=1;p_btn._visible=0;otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand }停止按钮动作:(隐藏)on(release){gotoAndStop(1);}鼠标拖拽:影片剪辑:on(press){this.startDrag(false);}on(release){this.stopDrag();}层:ball.onMouseDown=function(){if(this.hitTest(_xmouse,_ymouse,true)){this.startDrag(false);}};ball.onMouseUp=function(){};鼠标拖拽(2):在影片剪辑按钮层中按钮的动作为:on(press){startDrag("_root.a");}on(release){otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand stopDrag();}鼠标方位侦察(文本框名:xs_txt)varzc:Object=newObject();zc.onMouseMove=function(){xs_txt.text=_root._xmouse+","+_root._ymouse;};Mouse.addListener(zc);鼠标按下变量练习vari=0;xs_txt.text="这是按钮加减的结果:";//初始化赋值与文本jia_btn.onRelease=function(){i+=10;xs_txt.text="这是按钮加减的结果:"+i;};jian_btn.onRelease=function(){i-=10;xs_txt.text="这是按钮加减的结果:"+i;};跟随练习otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand 在要跟随的物体(转成MC)上写代码:onClipEvent (enterFrame) {  xTarget = _root._xmouse;  yTarget = _root._ymouse;  _x = xTarget;  _y = yTarget;}——————————————————————————————————————慢慢跟随过去:onClipEvent (enterFrame) {  xTarget = _root._xmouse;  yTarget = _root._ymouse;  fraction=0.5;  _x = _x + (xTarget-_x)*fraction;  _y = _y + (yTarget-_y)*fraction;  }——————————————————————————————————————————跟随时有幻影:1)物体做为MC,实列名为drag0,在MC上写代码:onClipEvent (enterFrame) { if (num) {  xTarget = eval("_root.drag"+(num-1))._x;  yTarget = eval("_root.drag"+(num-1))._y; } else {   xTarget = _root._xmouse;   yTarget = _root._ymouse; } fraction = .5; _x += (xTarget-_x)*fraction; _y += (yTarget-_y)*fraction;}在祯上面写代码:copies = 5;for (var i = 1; i<=copies; i++) {  duplicateMovieClip ("drag0", "drag"+i, i);  eval("drag"+i).num = i;}————————————otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand 2)直接在场景上放置了6个影片剪辑,依次实列命名为:drag0~drag5。然后在帧上添加代码如下:_root.drag0._x = _root._xmouse+10; _root.drag0._y = _root._ymouse;i = 1;while (i<=5) {  dragi = eval("/drag"+i);  dragi_prev = eval("/drag"+(i-1));  dragi._x += (dragi_prev._x-dragi._x)*0.5+10;  dragi._y += (dragi_prev._y-dragi._y)*0.5;  i = i+1;}在时间轴的第二帧插入帧(F5),因为只有至少2帧,动画才会产生循环,上面那些代码也才会重复运行,否则如果只有1帧的话,那些代码也就只被执行了一次。  1,新建元件1。画一线条。间隔20,40帧的位置插入1个关键帧,在第20帧进行扭曲变形(在没有被选的状态下,用黑色箭头工具,形状任意),各点选第一帧和第20帧创建“形状动画”。  2,回到场景,拖入元件1,实例名称“XZ”,选第一帧,打开动作,输入代码:i=1;xz="xz";while(i<150){duplicateMovieClip(xz,xz+i,i);setProperty(xz+i,_rotation,i*4);i++;}仅在帧上写代码:(没有鼠标箭号)onEnterFrame=function(){Mouse.hide();guaiguai._x+=_xmouse-guaiguai._x;guaiguai._y+=_ymouse-guaiguai._y;}模糊遮罩在场景1中建图层,层共4层。从下到上排列为:图1(p1)、图2(p2)、遮罩(pu1、pu2)、AS(p2.setMask(pu2);和p1.setMask(pu1);)。并为图层改相对应的名.属性:使用运行时位图缓存flash控制声音的暂停和继续播放otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand 1)将音乐导入到“库”中。右击“库”中的音乐对象,在弹出的快捷菜单中选择“链接”命令,打开“链接属性”对话框,勾选“为动作脚本导出”和“在第一帧导出”复选项,设置标识符为“mySound”。(2)在第1帧上添加如下脚本:myMusic=newSound();//建立一个名为myMusic的声音对象myMusic.attachSound("mySound");//将链接标识符为mySound的音乐捆绑到myMusic对象上(3)在播放音乐的按钮上添加如下脚本:on(press){vart=myMusic.position/1000;//计算声音当前播放的位置myMusic.start(t);//从当前位置开始播放}(4)加个停止按纽脚本:on(press){     stopAllSounds();}音量控制的制作一、按钮制作       1.新建元件:名称:按钮,行为:按钮。       2.在图层1的第一帧上画一个宽10,高15的无边框矩形,填充色任意二、滑动条制作       1.新建元件:名称:滑动条,行为:影片剪辑。       2.在滑动条元件的第一帧处从库里提进按钮,居中对齐。       3.选中按钮,打开动作面板,输入按钮动作:otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand        on(press){startDrag("_root.mc",true,right-100,top,right,top);}on(release){stopDrag();}  三、底线制作      1.新建元件:名称:底线,行为:图形。      2.在此元件的第一帧上画一个宽110(此宽度等于滑动条的宽度加100),高17的矩形条。填充色自定。居中对齐。四、音乐链接       1.导入声音文件到库。       2.打开库,在库里右键点声音文件,在下拉面板中,点链接,在链接属性面板里,链接选项选:作为动作脚本导出。然后在识符标栏里输入声音名:se,确定。五、场景组装      1把图层1名命为:底线。在此图层的第一帧上从库里提进底线图形元件,放到适当位置。(此位置自行安排)。      2.插入图层,命名为:文本。    (1)在此图层的第一帧处,建一个静态文本,并在文本里输入“音量”两字(字体,字色,字号自定)。把音乐两字放到你认为合适的位置。    (2)建一个动态文本,(字体,字色,自定,字号自定)。把此动态文本框放到音量两字的后面。    (3)选中动太文本框,在文本属性面板里输入变里名“vo”。     3.插入图层,命名为:控制条。    (1)在此图层的第一帧处从库里提进滑动条影片剪辑元件,并与底线矩形条右对齐。2)选中滑动条,在属性面板里输入实列名“mc”。    (3)选中滑动条,打开动作面板,输入影片剪辑动作:     onClipEvent(load){right=_x;top=_y;}onClipEvent(enterFrame){_root.vo=Math.round(_x-(right-100));_root.aa.setVolume(_root.vo);}otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand      4.插入图层,命名为:脚本。选中此图层的第一帧,打开动作面板,输入帧动作:        aa=newSound();aa.attachSound("se");aa.start(0,10);在flash中如何用按钮控制音乐播放方法如下:1.导入声音到舞台或者你想要的帧.2.选中库中的声音文件,单击鼠标右键,在弹出的菜单中选择“链接...”将会弹出一个链接的对话框,请勾选“为动作脚本导出”和“在第一桢导出”选项,并输入一个标识符(也就是声音文件的名字):mysound(名字可任意写),单击确定.3、回到主舞台,选中时间轴的第一桢,按F9打开动作面板。现在我们要创建一个新的声音对象,并且连接到库里的声音。用来控制声音。输入以下脚本:music=newSound();//创建一个名字叫music的声音对象。music.attachSound("mysound");//将这个声音对象与库里的标识符为“mysound”的声音连接。4、现在需要在舞台上放置两个按钮分别控制声音的播放与停止。选择“窗口”--“公用库”--“按钮”,打开flash为我们设置的公用按钮元件库,再将CircleButtons中的Play按钮和Stop按钮拖放到舞台上。或者你自己制作按钮.5、此时,舞台上将有播放和停止两个按钮,选中Play按钮,打开动作面板,输入以下脚本:on(release){music.start();}//播放声音选中Stop按钮,输入以下脚本:on(release){music.stop();}//停止播放声音otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand 6、OK,按Ctrl回车来测试吧6种常用的"一个按钮控制播放与暂停"的方法ps=0;//初始化ps,有些算法要用到。//循环算法-1on (release) { i++; if (i == 1) {  play(); } else {  stop(); } if (i>=2) { //当i=2时,让i=0,i就在1-0之间循环  i = 0; }}//绝对值算法-2on (release) {ps=Math.abs(ps-1)//计算绝对值psif(ps==0){play();}else{stop();}}on (release) {otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand ps=Math.abs(ps-1)//计算绝对值psif(ps==0){play();}else{stop();}}//非算法-真假判断法-3on (release) { if (!ps) { //非算法,非真等于假,非假等于真  stop();  ps = true;//或者ps=1;因为算法里1代表真0代表假 } else {  ps = false;//或者ps=0;  play(); }}//赋值算法(类似于第三种算法)-4on (release) { if (ps == 0) {  stop();  ps = 1; } else {  play();  ps = 0; }}//奇偶数的算法-5on (release) { if (ps%2 == 1) {otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand   play(); } else {  stop(); } ps++;}on (release) { if (ps%2 == 1) {  play(); } else {  stop(); } ps++;}//异或运算法-6on (release) {if(ps^1){ //异或:0异或1等于1,1异或1等于0。 stop();}else{ play();}ps++;if (ps>=2){ ps = 0;}}on (release) {otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand if(ps^1){ //异或:0异或1等于1,1异或1等于0。 stop();}else{ play();}ps++;if (ps>=2){ ps = 0;}}随机数:用Random函数Random函数在flash里是非常有用的,可以生成基本的随机数,创建随机的移动,以及随机的颜色和其他更多的作用。在下面这个例子中当你每次按下按钮就会显示一个从-100到100的随机数,这个教程将解释如何做出这个例子以及如何利用Random函数产生其他不同的结果。基本的Random函数如下Math.random();可以产生出0-1之间的任意小数,例如0.0105901374530933或0.872525005541986,有几个其他的函数可以用来改变产生的数字,从而可以更好的在你的影片中使用:Math.round();Math.ceil();Math.floor();这几个函数都是用来取得整数的,Math.round();是采用四舍五入方式取得最接近的整数。Math.ceil();是向上取得一个最接近的整数,Math.floor();和Math.ceil();相反,Math.floor();向下取得一个最接近的整数结合这些函数,你就可以这样写:Math.round(Math.random());这个表达式可以生成一个0.0和1.0之间的一个数,然后四舍五入取得一个整数。这样所生成的数字就是0或1。这个表达式可以用在各有50%的可能的情况下,例如抛硬币,或者true/false指令。otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand *10是将你所生成的小数乘以10,然后四舍五入取得一个整数:Math.round(Math.random()*10);要创建一个1到10之间的随机数,可以这样写:Math.ceil(Math.random()*10);应为是Math.ceil向上取值,所以不会产生0。要创建一个5到20的随机数可以这样写Math.round(Math.random()*15)+5;也就是说,如果要创建一个从x到y的随机数,就可以这样写Math.round(Math.random()*(y-x))+x;x和y可以是任何的数值,即使是负数也一样。要制作上面的那个例子,首先要创建一个按钮符号,拖动到主场景中,然后创建一个新的动态文本框,赋予动态文本框的变量名为“display”。创建的工作到此结束,下面来添加脚本.选中按钮,打开actions窗口,输入下面的代码,你可以在下拉菜单中选择,也可以直接将下面的代码拷贝进去:on(release){display=Math.round(Math.random()*200)-100;}完成了,下面测试一下你的影片,你会注意到代码中的值遵循了那个公式。如果x=-100,y=100,那么y-x=200,+x=-100.随机数在flash中还可以有多种不同的应用。要让一个movieclip在随机的屏幕上不同的位置上出现,显示的位置在0到200之间,可以这样写,注意movieclip的实例名为“bob”.bob._x=Math.round(Math.random()*200);bob._y=Math.round(Math.random()*200);或者随机的控制movieclip的大小(从0到100之间):bob._width=Math.round(Math.random()*100);otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand bob._height=Math.round(Math.random()*100);也可以随机的载入一个movieclip,如果你的movieclip的命名是"bob1","bob2"一直到"bob5",我们可以这样写。i=Math.ceil(Math.random()*5);attachMovie("bob"+i,"fred"+i,1);运行这个代码以后。就会随机的载入一个movieclip,例如"bob3",放在level1,赋予实例名为"fred3"。以上就是flash5中random函数的基本用法,希望你能运用到你的影片中去,创造出令人惊讶的flash作品。参考资料:http://dnm2008.blogspot.com/复制影片剪辑的属性语句的运用   复制影片剪辑duplicateMovieClip()语句运行后,可以通过setProperty()(属性)语句的运用,来达到自己所需要的效果。   下面通过气球特效说明一下运用属性语句的效果。   1、场景中只放入影片剪辑的效果:     2、将场景中的影片剪辑命名实例名称(此处命名为qqp_mc)。添加AS图层,在第二关键中写入代码:duplicateMovieClip("qqp_mc","qqp_mc"+i,i);i++;   (第一关键帧动作代码为i=1;第三关键帧动作代码为if(i>=120)otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand { gotoAndPlay(1);}else{ gotoAndPlay(2);}。下同。不再注明)   就是只复制影片剪辑,而不设定属性。效果如下:         显然,复制出来的影片剪辑始终在同一位置。   3。运用属性语句随机地改变复制出来的影片剪辑的坐标。在第二帧动作语句中加上这样的属性语句:setProperty("qqp_mc"+i,_x,random(550));setProperty("qqp_mc"+i,_y,random(100)+300);   即分别确定复制出来的影片剪辑的X轴和Y轴的坐标为random(550)和random(100)+300);运行后效果如下:       4、这样,位置效果不错了。可大小能不能变化呢?能。同样用属性语句。在第二关键帧动作中再加上下面的语句:myscale=random(50)+20;setProperty("qqp_mc"+i,_xscale,myscale);setProperty("qqp_mc"+i,_yscale,myscale);   就是随机产生一个数值,作为缩放比例。使新复制的影片剪辑按这个比例缩放。也就是随机地改变大小了。效果如下:otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand        5。还可以用属性语句来改变复制出来的影片剪辑的透明度,增强效果。在动作语句中再添加这样两句:myalpha=random(50)+50;setProperty("qqp_mc"+i,_alpha,myalpha);    效果如下:       6、但,颜色似乎太单调了吧!能否随机地改变颜色呢?能!但setProperty()代码语句没有颜色参数,无法用这个语句了。可以用构造函数创建对象的颜色属性。那就可以继续添加如下的语句:colorpy1=random(255);colorpy2=random(255);colorpy3=random(255);mycolor=newColor(eval("qqp_mc"+i));myobject={rb:colorpy1,gb:colorpy2,bb:colorpy3};mycolor.setTransform(myobject);   这就是随机产生三个255以内的随机数,分别作为复制出来的影片剪辑的红、绿、蓝三个颜色的偏移量。从而改变颜色。效果如下:   otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand    这样,效果是不是更好看更逼真了。这些,就是在复制影片剪辑时对属性语句setProperty()的运用。确实很有用的。otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。
大家都在看
近期热门
关闭