3/09/2011
as3 mouseEvent / ENTER_FRAME / if / addFrameScript
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class mainClass extends MovieClip
{
public function mainClass():void
{
this.addFrameScript(0, _addFrameScript0);
function _addFrameScript0():void{
trace("第一格");
}
this.ball.addFrameScript(29, _addFrameScriptxx);
function _addFrameScriptxx():void{
trace("ball最後一格");
}
ball.stop();
ball.addEventListener(MouseEvent.MOUSE_OVER,_OVER);//ball加上偵聽滑鼠上去按鈕
ball.addEventListener(MouseEvent.MOUSE_OUT,_OUT);//ball偵聽滑鼠離開按鈕
function _OVER(e:MouseEvent) {//定義涵式a
addEventListener(Event.ENTER_FRAME,_mouse_on);//偵聽ENTER_FRAME,執行_mouse_on涵式
removeEventListener(Event.ENTER_FRAME,_mouse_out);//移除偵聽_mouse_out
}
function _OUT(e:MouseEvent) {//定義涵式aa
addEventListener(Event.ENTER_FRAME,_mouse_out);//偵聽ENTER_FRAME,執行_mouse_out涵式
removeEventListener(Event.ENTER_FRAME,_mouse_on);//移除偵聽_mouse_on
}
ball.buttonMode=true;//按鈕模式打開,開了滑鼠icon就會變成手指
}
private function _mouse_on(e:Event) {//_mouse_on涵式
ball.nextFrame();
trace(ball.currentFrame);
if(ball.currentFrame==30){removeEventListener(Event.ENTER_FRAME,_mouse_on)}
}
private function _mouse_out(e:Event) {//_mouse_out涵式
ball.prevFrame();
trace(ball.currentFrame);
if(ball.currentFrame==1){removeEventListener(Event.ENTER_FRAME,_mouse_out)}
}
}
}
Labels:
as3
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment