SlideShare a Scribd company logo
1 of 66
Download to read offline
關於Event這回事
                                     there's something about Event




                                                        高見見龍龍
photo by Luke Peterson Photography
高見見龍龍
a.k.a Eddie or Aquarianboy
 Live and work in Taipei, Taiwan.
 Serving in my own little tiny company.
 Flash / AS3 / Ruby / Rails / Python programming for living.
 Mac OS user, Objective-C for personal inerests.
 Technical Education and Consulant.
 PTT Flash BM (since 2007/4).
 Ruby Certified Programmer (Since 2012/1).
 Adobe Certified Flash Developer (Since 2006/7).
 Linux Professional Institue Certification (Since 2005/3).     photo by Eddie
源起
why
如何與上(下)層的MC互動?
how to interact with parent (or child) movieclips?
想知道哪個按鈕被按了?
 how to know which button was clicked?
為什麼swf讀不到網路資料?
why swf file can not get the right response from the internet?
如何知道圖片已下載完成?
how to know if image files were downloaded completly?
事件
event
btn.onRelease = function() {
   _root.hero_mc.gotoAndPlay(10);
}
mc.onRelease = function() {
  _parent._parent.mc.title_txt.text = "this is not good!";
}
鬆綁
loose coupling
聆聽
listener
listener只是個function
    listener is just a function
function click_handler(e:MouseEvent):void {
   trace("hello, everyone!");
}
註冊
register
addEventListener
public function addEventListener(type:String, listener:Function,
useCapture:Boolean = false, priority:int = 0,
useWeakReference:Boolean = false):void
mc.addEventListener(MouseEvent.CLICK, click_handler);
名稱
event name
public function addEventListener(type:String, listener:Function,
useCapture:Boolean = false, priority:int = 0,
useWeakReference:Boolean = false):void
事件名稱其實只是字串
 event name is actually just plain string
trace(MouseEvent.CLICK);        // "click"
trace(IOErrorEvent.IO_ERROR);   // "ioError"
mc.addEventListener(MouseEvent.CLICK, click_handler);
mc.addEventListener("click", click_handler);
移除
remove
mc.removeEventListener(MouseEvent.CLICK, click_handler);
沒用到的記得要收掉
remember to remove useless listener
隨手做環保
save the world!
流程
flow
階段
phases
capture, bubble, and the target
photo by Luke Peterson Photography
reference: http://www.adobe.com/devnet/actionscript/articles/event_handling_as3.html
冒泡泡
 bubbling
dispatchEvent(new Event(Event.COMPLETE, bubbles:Boolean,
cancelable:Boolean));
捕捉
capture
public function addEventListener(type:String, listener:Function,
useCapture:Boolean = false, priority:int = 0,
useWeakReference:Boolean = false):void
mc.addEventListener(MouseEvent.CLICK, click_handler, true);
reference: http://www.adobe.com/devnet/actionscript/articles/event_handling_as3.html
參考
reference
addEventListener("click", function(e) { // code });
public function addEventListener(type:String, listener:Function,
useCapture:Boolean = false, priority:int = 0,
useWeakReference:Boolean = false):void
addEventListener("click", function(e) { // code }, false, 0, true);
順序
Priority
function handler_a(e:Event):void {
   trace("hello, A");
}

function handler_b(e:Event):void {
   trace("hello, B");
}

function handler_c(e:Event):void {
   trace("hello, C");
}

mc.addEventListener(MouseEvent.CLICK, handler_a);
mc.addEventListener(MouseEvent.CLICK, handler_b);
mc.addEventListener(MouseEvent.CLICK, handler_c);
public function addEventListener(type:String, listener:Function,
useCapture:Boolean = false, priority:int = 0,
useWeakReference:Boolean = false):void
mc.addEventListener(MouseEvent.CLICK, handler_a, false, 1);
mc.addEventListener(MouseEvent.CLICK, handler_b, false, 3);
mc.addEventListener(MouseEvent.CLICK, handler_c, false, 2);
目標
the target
target v.s. currentTarget
發布
dispatch
dispatchEvent(new MouseEvent(MouseEvent.CLICK));
客制化
custom events
package digik.events
{
    import flash.events.Event;
	

    public class LotteryEvent extends Event {

            public static const REMOVE_BANNER:String = "remove the banner";

            public var dataObject:Object;
	

   	

        public function LotteryEvent(type:String , dataObj:Object = null,
bubbles:Boolean = true, cancelable:Boolean = false, ...rest):void {
          super(type, bubbles, cancelable);
          dataObject = dataObj;
        }
	

 	

        override public function clone():Event {
          return new LotteryEvent(type, dataObject, bubbles, cancelable);
        }
    }
}
my_button.addEventListener(MouseEvent.CLICK, click_handler);

function click_handler(e:MouseEvent):void {
   dispatchEvent(new LotteryEvent(LotteryEvent.REMOVE_BANNER, {id: 2});
}
addEventListener(LotteryEvent.REMOVE_BANNER, banner_removed);
function banner_removed(e:LotteryEvent):void {
   trace(e.dataObject.id);
   var the_banner:Banner = this['banner_" + e.dataObject.id] as Banner;
   if (contains(the_banner)) {
       removeChild(the_banner);
   }
}
小結
conclusion
addEventListener(MouseEvent.CLICK, click_handler);
public function addEventListener(type:String, listener:Function,
useCapture:Boolean = false, priority:int = 0,
useWeakReference:Boolean = false):void
reference: http://www.adobe.com/devnet/actionscript/articles/event_handling_as3.html
用完記得要收
remember to remove useless listener
public function Lottery():void {
    if (stage) init();
    else addEventListener(Event.ADDED_TO_STAGE, added_to_stage);
}
	

 	

private function added_to_stage(e:Event):void {
    removeEventListener(Event.ADDED_TO_STAGE, added_to_stage);
    init();
}

private function init():void {
   // do something here
}
訊號
signal
結束
end
Conacts
高見見龍龍   Websie
        Blog
                   http://www.eddie.com.tw
                   http://blog.eddie.com.tw
        Plurk      http://www.plurk.com/aquarianboy
        Facebook   http://www.facebook.com/eddiekao
        Google Plus http://www.eddie.com.tw/+
        Twiter    https://twiter.com/#!/eddiekao
        Email      eddie@digik.com.tw
        Mobile     +886-928-617-687




                                                      photo by Eddie

More Related Content

Viewers also liked (14)

3rd AS Study Group
3rd AS Study Group3rd AS Study Group
3rd AS Study Group
 
Ruby without rails
Ruby without railsRuby without rails
Ruby without rails
 
Rails Girls in Taipei
Rails Girls in TaipeiRails Girls in Taipei
Rails Girls in Taipei
 
China in global music market
China in global music marketChina in global music market
China in global music market
 
AS3 Better Practices
AS3 Better PracticesAS3 Better Practices
AS3 Better Practices
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
測試
測試測試
測試
 
Flash Ecosystem and Open Source
Flash Ecosystem and Open SourceFlash Ecosystem and Open Source
Flash Ecosystem and Open Source
 
Code Reading
Code ReadingCode Reading
Code Reading
 
Rails girls in Taipei
Rails girls in TaipeiRails girls in Taipei
Rails girls in Taipei
 
AS3讀書會(行前準備)
AS3讀書會(行前準備)AS3讀書會(行前準備)
AS3讀書會(行前準備)
 
API Design
API DesignAPI Design
API Design
 
Misunderstanding about flash
Misunderstanding about flashMisunderstanding about flash
Misunderstanding about flash
 
from Ruby to Objective-C
from Ruby to Objective-Cfrom Ruby to Objective-C
from Ruby to Objective-C
 

Similar to There is something about Event

Asynchronous Programming with JavaScript
Asynchronous Programming with JavaScriptAsynchronous Programming with JavaScript
Asynchronous Programming with JavaScript
WebF
 

Similar to There is something about Event (20)

Signalsで Event処理を簡単に
Signalsで Event処理を簡単にSignalsで Event処理を簡単に
Signalsで Event処理を簡単に
 
2011 07-hiyoko
2011 07-hiyoko2011 07-hiyoko
2011 07-hiyoko
 
Yahoo presentation: JavaScript Events
Yahoo presentation: JavaScript EventsYahoo presentation: JavaScript Events
Yahoo presentation: JavaScript Events
 
Asynchronous Programming at Netflix
Asynchronous Programming at NetflixAsynchronous Programming at Netflix
Asynchronous Programming at Netflix
 
Desarrollo para Android con Groovy
Desarrollo para Android con GroovyDesarrollo para Android con Groovy
Desarrollo para Android con Groovy
 
Popup view on Mortar
Popup view on MortarPopup view on Mortar
Popup view on Mortar
 
Sbaw091117
Sbaw091117Sbaw091117
Sbaw091117
 
Voices That Matter: JavaScript Events
Voices That Matter: JavaScript EventsVoices That Matter: JavaScript Events
Voices That Matter: JavaScript Events
 
Asynchronous Programming with JavaScript
Asynchronous Programming with JavaScriptAsynchronous Programming with JavaScript
Asynchronous Programming with JavaScript
 
2009 Hackday Taiwan Yui
2009 Hackday Taiwan Yui2009 Hackday Taiwan Yui
2009 Hackday Taiwan Yui
 
JavaScript: Events Handling
JavaScript: Events HandlingJavaScript: Events Handling
JavaScript: Events Handling
 
Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...
Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...
Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGL
 
Dojo and Adobe AIR
Dojo and Adobe AIRDojo and Adobe AIR
Dojo and Adobe AIR
 
The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
YUI 3
YUI 3YUI 3
YUI 3
 
Virtual events in C#: something went wrong
Virtual events in C#: something went wrongVirtual events in C#: something went wrong
Virtual events in C#: something went wrong
 
Events
EventsEvents
Events
 
Foundational Facebook Marketing
Foundational Facebook MarketingFoundational Facebook Marketing
Foundational Facebook Marketing
 

More from Eddie Kao (12)

Let's Learn Ruby - Basic
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - Basic
 
iOS app development and Open Source
iOS app development and Open SourceiOS app development and Open Source
iOS app development and Open Source
 
Vim
VimVim
Vim
 
CreateJS - from Flash to Javascript
CreateJS - from Flash to JavascriptCreateJS - from Flash to Javascript
CreateJS - from Flash to Javascript
 
May the source_be_with_you
May the source_be_with_youMay the source_be_with_you
May the source_be_with_you
 
Why I use Vim
Why I use VimWhy I use Vim
Why I use Vim
 
Happy Programming with CoffeeScript
Happy Programming with CoffeeScriptHappy Programming with CoffeeScript
Happy Programming with CoffeeScript
 
CoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-TuesdayCoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-Tuesday
 
iOS Game Development with Cocos2d
iOS Game Development with Cocos2diOS Game Development with Cocos2d
iOS Game Development with Cocos2d
 
AMF
AMFAMF
AMF
 
Refactoring in AS3
Refactoring in AS3Refactoring in AS3
Refactoring in AS3
 
Test
TestTest
Test
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

There is something about Event