| | |
addEventListener Question
Please support our Graphics and Multimedia advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2007
Posts: 84
Reputation:
Solved Threads: 2
Hello everyone,
Trying to get a grasp on AS3.0. I know what addEventListerner is for and pretty much how to use it, but I the last three parameters in the statement have me scratching my head. There is a number (usually 0) and two Booleans--false and true respectively. Why are they there and do they ever change. If so, for what reasons(s)?
Thanks for your time in answering.
Trying to get a grasp on AS3.0. I know what addEventListerner is for and pretty much how to use it, but I the last three parameters in the statement have me scratching my head. There is a number (usually 0) and two Booleans--false and true respectively. Why are they there and do they ever change. If so, for what reasons(s)?
Thanks for your time in answering.
•
•
Join Date: Apr 2008
Posts: 22
Reputation:
Solved Threads: 4
Event listeners are usually set up this way:
So an example would be:
It sounds like you may be talking about events themselves, though. Events are created using the following syntax:
"Type" is the type of event and this can be constants (native to Flash such as '"MouseEvent.CLICK"') or custom types (created by you such as '"myCustomEventName"'). "Bubbles" refers to whether this event "bubbles" upward through the whole Flash application. Think of it this way: if an event "bubbles", it's as if the whatever triggered the event let out a bubble that floats upward through the Flash file and can be "seen" by the items above it. "Cancelable" refers to whether you can prevent the behavior associated with the event.
You can read all events and event listeners here: http://help.adobe.com/en_US/ActionSc...0204-7fca.html
Rock on!
--eric
Graphics and Multimedia Syntax (Toggle Plain Text)
addEventListener([event you're looking for],[function to trigger once event happens]);
So an example would be:
Graphics and Multimedia Syntax (Toggle Plain Text)
myButton.addEventListener(MouseEvent.CLICK, handleClick);
It sounds like you may be talking about events themselves, though. Events are created using the following syntax:
Graphics and Multimedia Syntax (Toggle Plain Text)
new Event(type:String, bubbles:Boolean, cancelable:Boolean)
"Type" is the type of event and this can be constants (native to Flash such as '"MouseEvent.CLICK"') or custom types (created by you such as '"myCustomEventName"'). "Bubbles" refers to whether this event "bubbles" upward through the whole Flash application. Think of it this way: if an event "bubbles", it's as if the whatever triggered the event let out a bubble that floats upward through the Flash file and can be "seen" by the items above it. "Cancelable" refers to whether you can prevent the behavior associated with the event.
You can read all events and event listeners here: http://help.adobe.com/en_US/ActionSc...0204-7fca.html
Rock on!
--eric
Eric Oliver
www.thecosmonaut.com
www.thecosmonaut.com
•
•
Join Date: Jul 2007
Posts: 84
Reputation:
Solved Threads: 2
ok...I looked at the website you gave me and apparently there is a separate class called the IEventDispatcher class which contains more parameters. I must also add, however, that I am now more confused and don't know which to use and when when I am add an even listener. I originally thought the 3 parameter listener was sufficient with [event.event_type, function]. It seems there are additional conditions to consider adding, as I said, to my confusion.
•
•
Join Date: Apr 2008
Posts: 22
Reputation:
Solved Threads: 4
Hey there!
Whoops - added confusion is not the goal
Maybe a different way to approach it would be to be more specific about what you're trying to achieve. Do you want to add event listeners to buttons? To functions? Can you explain a little more the problem you're tackling?
As a general overview, in AS3 you add event listeners whenever you want to track if some sort of event has happened and then have the program do something in response. For example, if you want to have the function "loadContent1()" get triggered whenever someone has clicked "button1", you would add the following code:
AS3 has events for pretty much everything: all the mouse behaviors (roll over, roll out, click, move, etc.), generic events (load, complete, etc.), and events specific to certain classes (data loading events, sound events, etc.). And if Flash's native events aren't enough, you can even add custom events if you like using the Event class.
The IEventDispatcher class is an INTERFACE, which you only will use in situations when you can't extend the EventDispatcher class (for example, if the class you're building is already extending another class). This all involves a deeper layer of complexity, so to avoid confusion, you should probably ignore the IEventDispatcher class for now and count on using the simple "addEventListener([event.event_type], [function])"
So to recap: Ignore IEventDispatcher for now, and focus on adding event listeners via "addEventListener([event.event_type], [function])", which you will use for most any scenario where you want to trigger a function if some sort of action/event takes place.
Best,
--eric
Whoops - added confusion is not the goal
Maybe a different way to approach it would be to be more specific about what you're trying to achieve. Do you want to add event listeners to buttons? To functions? Can you explain a little more the problem you're tackling?
As a general overview, in AS3 you add event listeners whenever you want to track if some sort of event has happened and then have the program do something in response. For example, if you want to have the function "loadContent1()" get triggered whenever someone has clicked "button1", you would add the following code:
Graphics and Multimedia Syntax (Toggle Plain Text)
button1.addEventListener(MouseEvent.CLICK, loadContent1); function loadContent1():void { //Function info goes here }
AS3 has events for pretty much everything: all the mouse behaviors (roll over, roll out, click, move, etc.), generic events (load, complete, etc.), and events specific to certain classes (data loading events, sound events, etc.). And if Flash's native events aren't enough, you can even add custom events if you like using the Event class.
The IEventDispatcher class is an INTERFACE, which you only will use in situations when you can't extend the EventDispatcher class (for example, if the class you're building is already extending another class). This all involves a deeper layer of complexity, so to avoid confusion, you should probably ignore the IEventDispatcher class for now and count on using the simple "addEventListener([event.event_type], [function])"
So to recap: Ignore IEventDispatcher for now, and focus on adding event listeners via "addEventListener([event.event_type], [function])", which you will use for most any scenario where you want to trigger a function if some sort of action/event takes place.
Best,
--eric
Eric Oliver
www.thecosmonaut.com
www.thecosmonaut.com
![]() |
Similar Threads
- JavaScript's window.opener (JavaScript / DHTML / AJAX)
- looking for a script for menubar (JavaScript / DHTML / AJAX)
Other Threads in the Graphics and Multimedia Forum
- Previous Thread: Actionscript - load variable from external .txt
- Next Thread: Scolling Images
| Thread Tools | Search this Thread |
3d 10 actionscript3 adobe adobeacrobat adobereader air ajax amazon amf apple button cart childprotection cloud dashboard dell design dojofoundation dreamweaver ebay eclipse ecommerce elasticcomputecloud embed endorsement extra family flash flash-develop flashlite flex free harddrive iamthwee ibm illustrator imflash intel interactivemap javafx javascript laptop legal map micron microsoft mobile monitoringsoftware moonlight multimedia myspace nand news novell panorama pdf pedophiles photoshop photosynth php safety sandisk security shopping silverlight solidstatedrive sproutcore ssd streaming swf table ukmap unload unwanted video vulnerability web white.space xml zend zephyr zeroday





