JBTALKS.CC

标题: [教學]如何控制好Flash效果 [打印本页]

作者: Super-Tomato    时间: 2007-7-18 08:42 PM
标题: [教學]如何控制好Flash效果
作者 : 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 一併移除掉. 不是更加省事嗎?
作者: 03-342    时间: 2007-7-19 04:59 PM
哇?好难哦?这些code是你自己想出来的?佩服~!你怎么知道该打什么指令啊?
作者: Super-Tomato    时间: 2007-7-19 09:45 PM
原帖由 03-342 于 2007-7-19 04:59 PM 发表
哇?好难哦?这些code是你自己想出来的?佩服~!你怎么知道该打什么指令啊?



基礎學會了, 多練習就會知道許要甚麼函數和怎麼使用.
作者: $tar17    时间: 2009-4-9 10:29 PM
标题: 回复 #1 Super-Tomato 的帖子
这些要用在哪里?
em0010 em0010
作者: Super-Tomato    时间: 2009-4-10 11:39 AM
原帖由 $tar17 于 2009-4-9 10:29 PM 发表
这些要用在哪里?
em0010 em0010




標題已經說明使用於  Flash
作者: 宅男-兜着走    时间: 2010-3-13 01:31 PM
标题: 回复 #1 Super-Tomato 的帖子
哈~ 原来还有这个贴。 感谢教学。
作者: 屎上最强    时间: 2011-6-14 11:52 PM
乱 , 哪里还需要那么麻烦。。。
作者: raven6980    时间: 2011-6-16 09:51 PM
楼主!!!我现在学着HTML!!!觉得不是很难!!!FLASH是不是比较难呢???
作者: wallencechen    时间: 2011-6-17 04:32 PM
好厉害,谢谢分享




欢迎光临 JBTALKS.CC (https://www.jbtalks.cc/) Powered by Discuz! X2.5