PDA

View Full Version : How to reference the object listening for event?



johnlouis
April 13th, 2008, 11:33 PM
i want to make a preloading function that could be used by any Loader object I have regardless of name. I'll explain in code



loader1.contentLoaderInfo.addEventListener(Progres sEvent.PROGRESS, loadProgress);
loader2.contentLoaderInfo.addEventListener(Progres sEvent.PROGRESS, loadProgress);
loader1.contentLoaderInfo.addEventListener(Event.C OMPLETE, loadComplete);
loader2.contentLoaderInfo.addEventListener(Event.C OMPLETE, loadComplete);


function loadProgress(e:Event):void{
//how do i get a reference of the object that is calling this function?
trace(targetObject.bytesLoaded); //i want to reference the contentLoaderInfo of the Loader currently using this method
}

function loadComplete(e:Event):void{
addChild(targetObject.parent); //not sure if that's logical
}

I hope i'm making sense. :book:

Anogar
April 14th, 2008, 12:50 AM
e.target

:thumb:

hobbbz
April 14th, 2008, 12:58 AM
e.currentTarget

johnlouis
April 14th, 2008, 10:00 AM
thanks guys. is currentTarget the same as target?

EDIT: I tried this code:
ActionScript Code:

function moveBox(e:Event):void{
this.x += 1;
}
box.addEventListener(Event.ENTER_FRAME, moveBox);




it seems to work fine..
so, which one should I use? this, target, or currentTarget?

Felixz
April 14th, 2008, 04:06 PM
target is pointing to object receiving an event, currentTarget points to object where listener is added.
This difference helps handling bubbling events