Reputation: 1
can you please help me to find what does e: mean in actionscript 3.0 ?
my_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, startListener);
function startListener (e:Event):void;
Upvotes: 0
Views: 431
Reputation: 4750
e
is the Event that was dispatched.
You have an object that's called / referenced by my_loader.contentLoaderInfo
. At some point, my_loader.contentLoaderInfo
might create an Event
object, categorize it as a "complete event" (in other words, Event.COMPLETE
), and dispatch it to any functions listening to my_loader.contentLoaderInfo
for an Event.COMPLETE
event. This is done by calling the functions that are listening for that event.
In this case startListener
is one of those functions that's listening for that event on my_loader.contentLoaderInfo
, so whenever that kind of event is dispatched from that object, one of the functions that's called is startListener
. Notice how the type of object that is dispatched and the type for startListener's
lone parameter are the same: Event
.
A function that's listening to an object for a type of event may wish to examine the event for certain pieces of information, so when that event is dispatched, it is copied by reference to the listening function as the lone argument. So e
is a reference to the event that was created and dispatched.
This next little bit may be jumping ahead, but this is an example of how that might be used: One thing some people like to do is to make the same function listen to multiple objects for the same type of event. Something like:
obj1.addEventListener(Event.COMPLETE, myHandler);
obj2.addEventListener(Event.COMPLETE, myHandler);
obj3.addEventListener(Event.COMPLETE, myHandler);
function myHandler(e:Event):void {
// do some stuff
}
So what if one of those objects dispatches a complete event? How does myHandler
know which object it belongs to? By looking at e.target
:
function myHandler(e:Event):void {
this.doSomething(e.target);
}
e.target
is the actual object that dispatched the event, so if the function is listening to multiple objects for the same type of event, e.target
would let the function tell those objects apart.
Upvotes: 1
Reputation: 1193
It's a parameter you passes in your custom function e.g.
//Here, data type is a Number
and var name is myNum
function doSquare(myNum:Number):void
{
var mySquare:Number = myNum * myNum;
}
Similarly,
//here type is Event
and var name is e
(you can have any name like evt, event, myEvt etc)
function startListener (e:Event):void
{
trace(e.target.content.width);
trace(e.target.width);
trace(my_loader.width);
}
Upvotes: 0
Reputation: 601
Event listeners (your function startListener
) must receive an Event object. Generally this is written as e:Event
but could just as easily be hamSandwich:Event
. The important part is that it is an Event object.
Upvotes: 1