PDA

View Full Version : calling parents


stewart.matheson
08-01-2008, 12:12 AM
Hi Actionscriptors!

I have a class that loads an xml file. I want to set this class up to call the a method in the document class when it has done loading. So i need to point an event at a method with in a parent of a parent. I have tried using

this.xmlLoader.addEventListener(ProgressEvent.PROG RESS, (this.parent.parent as MovieClip).update_progress);

for my preloader but i get a comple error. What am i doing wrong?

Thanks

Stewart

stewart.matheson
08-01-2008, 12:14 AM
oh this is the error i get

1119: Access of possibly undefined property parent through a reference with static type PFFXMLLoader.

FYI

lordofduct
08-01-2008, 12:34 AM
parent is a property with respect to DisplayObjectContainer first off. It's the container that the object is visually inside of.

Second off, that is a kind of dirty way of doing it. How about firing an event and having the 'parent class' listen for it perform the job it's supposed to when it is done.

stewart.matheson
08-01-2008, 12:37 AM
parent is a property with respect to DisplayObjectContainer first off. It's the container that the object is visually inside of.

Second off, that is a kind of dirty way of doing it. How about firing an event and having the 'parent class' listen for it perform the job it's supposed to when it is done.

do i fire the event in the same way? How do i set my parent class up to listen to an event?

lordofduct
08-01-2008, 01:00 AM
as long as the class firing implements or inherits from an EventDispatcher.

in the class that fires:


dispatchEvent(new Event("myEventToListenFor")); //you can name it any string you want


in parent class:

myObjectThatFiresEvent.addEventListener("myEventToListenFor", functionToFire);

function functionToFire(e:Event):void
{
...
}