author: senocular [+], Submitted: 12.03.02 6a • Last Edit: 03.04.05 6a
Avg. Rating: 4

usage

msg1 { pius [+], posted: 04.08.03 1a•-, top [^] }
shouldn't there only be one ASB, that broadcasts various events and the listeners evaluate the event and react in their specific way. I can hardly get why there should be more ...
msg2 { senocular [+], posted: 04.08.03 4a•04.08.03 4a, top [^] }
Youd have more for seperate events. There are already preset broadcasters in Flash; objects like Key, Mouse, Stage, etc. are already broadcasters. The reason there isnt only one is because that single broadcaster would have to then go through every listener there is to send out one single message, even though you might only need the objects which recognize the onKeyDown to recieve the message. That is why you dont add the onKeyDown objects to the Mouse broadcaster when you want that object's onKeyDown to be called when the key is pressed. You'd only add it as a listener of the Key object since its what sends out the onKeyDown event.

When you set up your own broadcasters/listeners, you'd want to group them together to have broadcasters only have listeners which need to listen to it and not listeners which dont... if you get what Im saying... For example:

Lets say you have 2 sets of objects. Apples and Oranges (the conceptual purposes ;). Apples become apple sauce, but Oranges are made into orange juice. However, both need to first be picked from the tree. Right away though, you can see that Oranges dont get made into apple sauce and Apples arent made into orange juice, so there would be no reason to tell them to do so. Instead, youd just broadcast the apple sauce event to only the Apples and broadcast the orange juice event to only the Oranges. The picking of the each however, is done to all of them. In that case, you can handle the picking by going through each fruit individually and calling the pick event, or you can just have one broadcaster to handle all fruit. So you might have something like (simple ex):




So here you have your 2 objects, apples and oranges (and they all inherit from the Fruit superclass since they are all fruit). Each has their own Make method for whatever it is they will become and they all inherit the pickme method. Now, the broadcasters defined are AllFruit, AllApples, and AllOranges. Why are there more than one? Because we wont want to send all the apples the oranges event when we broadcast makeOrangeJuice. Thats that many objects the broadcaster has to enumerate through to call the method on (which in the apples dont even have). The fruit broadcaster though, does have each apple and orange in it - but this is needed since they all need to be picked... having the seperate allapples and alloranges let you optimize the use of the broadcaster (instead of using allfruit) as it only cycles through those objects you need it too.

Here, actually, its a little flicted because with this type of inheritance (and no check in the constructor) the prototypes of the apples and oranges are added the the allfruit broadcaster as well, but this is just a simple example to show how you would use more than one broadcaster. Even here though, there is a close relation between the listener objects. Chances are you could have completely seperate kinds of objects with no relation to each other whatso ever which would necessitate the use of more than one broadcaster... Otherwise why make broadcasters yourself at all? You the Mouse of the Key object (actually I often use the Stage if I only need one broadcaster since it already is one and it only handles the onResize event which usually never gets called anyway)
msg3 { sBirro [+], posted: 03.04.05 6a•-, top [^] }
nice job senocular, but how can i do this to work in MX 2004?

thx in advance
msg4 { senocular [+], posted: 03.04.05 6a•03.04.05 6a, top [^] }
I changed a case sensitive issue that would have affected MX 2004. It should work now.
buy wow gold abendkleider online cocktail dresses uk woolrich outlet clarisonic pro long prom dresses