ftp://nas.takming.edu.tw/songshen/ftp/FlashAS3/A/
設計概念
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0zB9IvtpnHFlq27iJnt1b_jPA97diLXL5JqZqq30PdTx8ZSHCEpUbihJoj-DROF6H-BRuOaelCro3wnjzFALV2osHiOgy_9urSah9sVZX8TCojg-s1dQvcTI3Ug_n-G0yIeU80sTMkYw/s1600/%E5%BD%B1%E6%A0%BC.png)
注意事項:寫程式物件用選的。
用↓選
影片片段Code
>> 要讓走路走10次之後回到原本靜止的狀態。影格1 stop(),並宣告i。
stop()影格10 按F7,之後F9,輸入i=i+1;
var i:int=0;
i=i+1;影格24 按F7,之後F9,寫if判斷式,i<=10跳至影格10繼續播,否則跳至影格1並停止。
if(i<=10)影格32
{
this.gotoAndPlay("_walk")
}else{
this.gotoAndStop("_stand")
}
i=i+1;影格42
if(i<=10)
{
this.gotoAndPlay("_jump")
}
控制Code
滑鼠滑過、按下可以跑跳pig.addEventListener(MouseEvent.MOUSE_OVER, pigover);
pig.addEventListener(MouseEvent.CLICK, pigjump);
function pigover(e:MouseEvent):void
{
this.pig.gotoAndPlay("_walk")
}
function pigjump(e:MouseEvent):void
{
this.pig.gotoAndPlay("_jump")
}
避免重跳、互相干擾 _ 方法1
pig.addEventListener(MouseEvent.MOUSE_OVER, pigover);避免重跳、互相干擾 _ 方法2
pig.addEventListener(MouseEvent.CLICK, pigjump);
function pigover(e:MouseEvent):void
{
if (Object(this).pig.currentFrame == 1) {
Object(this).pig.i = 0;
this.pig.gotoAndPlay("_walk");
}
}
function pigjump(e:MouseEvent):void
{
if (Object(this).pig.currentFrame < 25) {
Object(this).pig.i = 0;
this.pig.gotoAndPlay("_jump");
}
}
取消登記,將addevent在function中remove。
EX.
this.removeEventListener(MouseEvent.MOUSE_OVER, thisover);
為了提供大量複製功用,將程式複製至影片片段的影格1。
最後完整的Code
stop();
var i:int = 0;
this.addEventListener(MouseEvent.MOUSE_OVER, thisover);
this.addEventListener(MouseEvent.CLICK, thisjump);
function thisover(e:MouseEvent):void
{
this.removeEventListener(MouseEvent.MOUSE_OVER, thisover);
this.i = 0;
this.gotoAndPlay("_walk");
}
function thisjump(e:MouseEvent):void
{
this.removeEventListener(MouseEvent.CLICK, thisjump);
this.i = 0;
this.gotoAndPlay("_jump");
}
沒有留言:
張貼留言