views:

23

answers:

1

Hi guys, I have learned as3 for a half years, these days I found I always have the trouble that make different classes communicate with each other.

I kinda figure out there are some ways to solve (if I am wrong, please tell me...): 1. using get set methods 2. eventdispatch to dispatch custom event.

Today, I am working on this confused issue again. I still can't get through it. this time what I wanna do is this: I wanna use a button (_zoom) to control a mc (_board) located in different class. Let's me give a simple structure for you:

ProjectAppear.as
  |_   _board (mc)
  |_   Project.as
            |_   _work (mc)
                      |_   _zoom (mc)

My thought is I add a mouse event listener for _zoom, and then when mouse click it will dispatch a custom event, and then .... I get lost in here....

A: 

So if you're dispatching your custom event in the Project class that contains the _zoom mc, and ProjectAppear has a reference to both Project and to _board, then inside ProjectAppear you can add an event listener to Project for the custom event (myProject.addEventListener("myCustomEvent", eventHandler, etc....) and in the eventHandler function (which will have a reference to both _board and Project since it's in ProjectAppear) you can do whatever you need to with _board. Hope that helps!

quoo
zomg i have a unicorn avatar. can i keep this?
quoo