Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 3872|回复: 8
打印 上一主题 下一主题

[教學]如何控制好Flash效果

 关闭 [复制链接]

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

跳转到指定楼层
1#
发表于 2007-7-18 08:42 PM |只看该作者 |倒序浏览
作者 : Super-Tomato


這篇並不是一步步的教你如何製作任何效果, 只是要提醒那些從別處網站得到coding後依樣畫葫蘆得到了效果卻不會讓效果消失的朋友, 如何以比較好的方式來控制. 以下是從別處拿來的花瓣飄落效果.


mover = function () {
this._y += this.k;
this._x += this.wind;
if (this._y>height+10) {
  this._y = -20;
}
if (this._x>width+20) {
  this._x = -(width/2)+Math.random()*(1.5*width);
  this._y = -20;
} else if (this._x<-20) {
  this._x = -(width/2)+Math.random()*(1.5*width);
  this._y = -20;
}
};
init = function () {
width = 800;  // pixels
height = 600; // pixels
max_snowsize = 5; // pixels
snowflakes = 30; // quantity
for (i=0; i<snowflakes; i++) {
  t = attachMovie("sakura", "sakura"+i, i);
  t._alpha = 20+Math.random()*60;
  t._x = -(width/2)+Math.random()*(1.5*width);
  t._y = -(height/2)+Math.random()*(1.5*height);
  t._xscale = t._yscale=50+Math.random()*(max_snowsize*10);
  t.k = 3+Math.random()*2;
  t.wind = -3.5+Math.random()*(1.4*3);

  //這裡開始花瓣會通過onEnterFrame的事件不停的在執行
  t.onEnterFrame = mover;
}
};
init();



以這樣的方式在之後的50個frame之後加上 stop(); 指令的話只能讓frame停止播放, 但花瓣的飄落卻無法停止, 原因就是出在onEnterFrame 這個 event 上. 要讓花瓣停止的為一方法就是要停止這個 onEnterFrame, 那麼能夠做的就是 1.刪除 onEnterFrame 事件, 2. 刪除所有花瓣, 那麼每片花瓣所擁有的屬性和事件也會一併的刪除.

當然我們會選擇第二的方法, 直接把花瓣刪除, 不然你讓花瓣停止了卻不消失有何用?
所以你就必須取得目前製作了多少片花瓣, snowflakes的數量, 然後再通過 for loop 把所有的花瓣removeMovieClip. 如:



for (i=0; i<snowflakes; i++) this["sakura"+i].removeMovieClip();



這樣雖然沒問題.... 但在製作一個比較大型的 flash 時, 你不可能會把所有的 variable 都記住. 要提升自己的製作速度就必須把所有東西都規劃好, 那麼你就該這樣做.


mover = function () {
this._y += this.k;
this._x += this.wind;
if (this._y>height+10) {
  this._y = -20;
}
if (this._x>width+20) {
  this._x = -(width/2)+Math.random()*(1.5*width);
  this._y = -20;
} else if (this._x<-20) {
  this._x = -(width/2)+Math.random()*(1.5*width);
  this._y = -20;
}
};
init = function () {
width = 800;  // pixels
height = 600; // pixels
max_snowsize = 5; // pixels
snowflakes = 30; // quantity

//建立一個叫sakura的空MovieClip.
this.createEmptyMovieClip("sakura", this.getNextHighestDepth());

for (i=0; i<snowflakes; i++) {
  //把所有的花瓣attach到這個sakura空MovieClip中.
  t = sakura.attachMovie("sakura", "sakura"+i, i);
  t._alpha = 20+Math.random()*60;
  t._x = -(width/2)+Math.random()*(1.5*width);
  t._y = -(height/2)+Math.random()*(1.5*height);
  t._xscale = t._yscale=50+Math.random()*(max_snowsize*10);
  t.k = 3+Math.random()*2;
  t.wind = -3.5+Math.random()*(1.4*3);
  t.onEnterFrame = mover;
}
};
init();



那麼這樣一來你就只要記住這個效果叫 sakura, 其他的一概不管. 在要停止的時候就使用

sakura.removeMovieClip();


這樣的一句就可以把 sakura 和其所蓋括的 movieclip 一併移除掉. 不是更加省事嗎?




收藏收藏0

51

主题

3

好友

5261

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

2#
发表于 2007-7-19 04:59 PM |只看该作者
哇?好难哦?这些code是你自己想出来的?佩服~!你怎么知道该打什么指令啊?


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

3#
发表于 2007-7-19 09:45 PM |只看该作者
原帖由 03-342 于 2007-7-19 04:59 PM 发表
哇?好难哦?这些code是你自己想出来的?佩服~!你怎么知道该打什么指令啊?



基礎學會了, 多練習就會知道許要甚麼函數和怎麼使用.


回复

使用道具 举报

0

主题

0

好友

31

积分

初级会员

Rank: 1

4#
发表于 2009-4-9 10:29 PM |只看该作者

回复 #1 Super-Tomato 的帖子

这些要用在哪里?
em0010 em0010


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

5#
发表于 2009-4-10 11:39 AM |只看该作者
原帖由 $tar17 于 2009-4-9 10:29 PM 发表
这些要用在哪里?
em0010 em0010




標題已經說明使用於  Flash


回复

使用道具 举报

46

主题

6

好友

6456

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

6#
发表于 2010-3-13 01:31 PM |只看该作者

回复 #1 Super-Tomato 的帖子

哈~ 原来还有这个贴。 感谢教学。


回复

使用道具 举报

3

主题

0

好友

45

积分

初级会员

Rank: 1

7#
发表于 2011-6-14 11:52 PM |只看该作者
乱 , 哪里还需要那么麻烦。。。


回复

使用道具 举报

15

主题

0

好友

54

积分

中级会员

Rank: 2Rank: 2

8#
发表于 2011-6-16 09:51 PM |只看该作者
楼主!!!我现在学着HTML!!!觉得不是很难!!!FLASH是不是比较难呢???


回复

使用道具 举报

0

主题

0

好友

10

积分

初级会员

Rank: 1

9#
发表于 2011-6-17 04:32 PM |只看该作者
好厉害,谢谢分享


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-7-1 04:40 PM , Processed in 0.193251 second(s), 27 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部