PDA

View Full Version : sharing dispatched events



RossKidd
April 7th, 2009, 03:08 PM
Hi,

I have two classes, classA and classB


classA is created on the maintimeline

var myClass:ClassA = new ClassA();
addChild(myClass);

one of the methods dispatches an event

dispatchEvent(new Event("createdIt")

How do I create an eventListener for this event in classB?

baggins825
April 7th, 2009, 03:19 PM
why not just add a call to the function you want to execute in Class B within the function that occurs when the event is dispatched in Class A?

RossKidd
April 7th, 2009, 03:44 PM
I try and excute it within the function with thenameoftheclass.method()

ClassA.onClick();

I get

TypeError: Error #1006: onClick is not a function.


I can refer to a method the via an instance

MovieClip(parent.instanceName.onClick();

Can I call it directly?Is that what you are saying?

dandylion13
April 7th, 2009, 09:45 PM
Is ClassB linked to a display object on the stage?

RossKidd
April 8th, 2009, 02:08 AM
It is actually a button class so is linked to 4 items