943,516 Members | Top Members by Rank

Ad:
Nov 18th, 2008
0

addEventListener Question

Expand Post »
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.
Similar Threads
Reputation Points: 11
Solved Threads: 3
Junior Poster
Reliable is offline Offline
152 posts
since Jul 2007
Nov 23rd, 2008
0

Re: addEventListener Question

Event listeners are usually set up this way:

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. addEventListener([event you're looking for],[function to trigger once event happens]);
  2.  

So an example would be:
Graphics and Multimedia Syntax (Toggle Plain Text)
  1. 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)
  1. 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
Reputation Points: 10
Solved Threads: 4
Newbie Poster
erico564 is offline Offline
22 posts
since Apr 2008
Nov 24th, 2008
0

Re: addEventListener Question

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.
Reputation Points: 11
Solved Threads: 3
Junior Poster
Reliable is offline Offline
152 posts
since Jul 2007
Nov 24th, 2008
0

Re: addEventListener Question

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:

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. button1.addEventListener(MouseEvent.CLICK, loadContent1);
  2. function loadContent1():void
  3. {
  4. //Function info goes here
  5. }

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
Reputation Points: 10
Solved Threads: 4
Newbie Poster
erico564 is offline Offline
22 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Graphics and Multimedia Forum Timeline: Actionscript - load variable from external .txt
Next Thread in Graphics and Multimedia Forum Timeline: Scolling Images





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC