物件name.addEventListener(Event.ENTER_FRAME, function_name);
functoin function_name(event:Event):void {
..............
}
function 函數名(參數1:資料型態,參數2:資料行態,.....):傳回值資料型態{ }
若沒有指定傳回值則為void
====================================================================
EventListerner事件監聽器;接收事件時addEventListener();刪除時removeEventListerner();
my_mc.addEventListener(MouseEvent.ROLL_OVER, mouseStateHandler);
my_mc.addEventListener(MouseEvent.ROLL_OUT, mouseStateHandler);
my_mc.addEventListener(MouseEvent.CLICK, clickHandler);
function mouseStateHandler(event:MouseEvent):void {
switch (event.type) {
case MouseEvent.ROLL_OVER :
output_txt.text = "ROLL_OVER!";
break;
case MouseEvent.ROLL_OUT :
output_txt.text = "ROLL_OUT!";
break;
}
}
function clickHandler(event:MouseEvent):void {
output_txt.text = "";
my_mc.removeEventListener(MouseEvent.ROLL_OVER, mouseStateHandler);
my_mc.removeEventListener(MouseEvent.ROLL_OUT, mouseStateHandler);
my_mc.removeEventListener(MouseEvent.CLICK, clickHandler);
}
==================================================================
檢查事件監聽器是否已登錄
mc.hasEventListener(Event.ENTER_FRAME)
檢查事件目標(其實就是物件)
event.target (指物件裡的零件)
event.currentTarget (指物件)
該屬性有x,y,width,height,name........
==================================================================
Flash Player動態/非動態
指的是是否焦點在此視窗上
(運用上像Funtown的牌桌,一離開視窗就會沒音樂,但一點選又繼續播放)
my_mc.addEventListerner(event.ACTIVATE, function_name1);
my_mc.addEventListerner(event.DEACTIVATE, function_name2);
主要就是如果現在player是在焦點上就會做function_name1的事;不是就會function_name2
==================================================================
透明度&顯不顯示
mcStar.alpha = 1 (全亮) ~ 0 (透明);
mcStar.visible = true ; false;
要提取成文字時String(mcStar.alpha);, String(mcStar.visible);
==================================================================
/* 阿斗自習 */
三個物件: inText,outText,myBtn
var newURL:String = "http://www.yahoo.com.tw";
myBtn.addEventListener(MouseEvent.CLICK, gotheURL);
function gotheURL(event:MouseEvent):void{
var adobeURL:URLRequest = new URLRequest(newURL);
navigateToURL(adobeURL);
}
inText.addEventListener(TextEvent.TEXT_INPUT, changeURL);
function changeURL(item:TextEvent):void{
if(item.text == ";"){
newURL = "http://";
} else {
newURL += item.text;
}
outText.text = "New URL:" + newURL;
}
自行輸入想要的URL,按下Btn就會連結!!
==================================================================
沒有留言:
張貼留言