Sending data with events...

12 views
Skip to first unread message

Devon

unread,
Jul 2, 2012, 3:29:41 AM7/2/12
to eventco...@googlegroups.com
Hey, how would I go about sending an object with the event? For example, I may want to send an event about a player scoring to update a scoreboard - how would I send the new score along with the event?

Thanks!

Ben Fhala

unread,
Jul 2, 2012, 8:51:20 AM7/2/12
to eventco...@googlegroups.com
That's a really good question.

Mmm tricky yea good question to get this to work you would need to modify your object as well as created a modified event and then modify the EventController -that's to much modifying!

instead of that probably the easiest way to get around it is not to send more things to the event just store the information in the object that is triggering the event and then in the event get the info

function onEvent(e:Event):void{
     trace(e.target.parameterName);
}


then you don't need to change anything in the flow right now there is no way to add extra parameters into the EventController but it can be added in really easy its just not there for file size constrains (wanted to keep the file as small as possible)
if you perffer working with passing parameters you would need to update a nice amount of things - let me know if option 1 didn't work for you if it didn't i can create an alternative EventController for you but i think the way it is is probably easier as you wouldn't need to change any classes on your end.



--
Thanks,

Ben Fhala
02Geek.com
HTML5, Javascript, ActionScript & Flash School
follow us on  @02Geek  ][  Subscribe to  Youtube  ][ Like us on FaceBook

02Geek is part of Everything Nice ,inc creations.


On Mon, Jul 2, 2012 at 3:29 AM, Devon <devo...@msn.com> wrote:
Hey, how would I go about sending an object with the event? For example, I may want to send an event about a player scoring to update a scoreboard - how would I send the new score along with the event?

Thanks!





Devon

unread,
Jul 2, 2012, 6:54:53 PM7/2/12
to eventco...@googlegroups.com
Oh, I didn't even think of that - I'll give it a try later...

Meanwhile, I'm still a bit confused on how to use this class. Your examples and videos show how they're used when events are dispatched automatically within' the same class. How would I dispatch a custom event from an unrelated class?

Thanks again! :)

Ben Fhala

unread,
Jul 2, 2012, 10:01:52 PM7/2/12
to eventco...@googlegroups.com
no worries ;)

well the idea of the class is to break the rules of programing really all the other event management classes try to do things legally while we are trying to do it easily :) some classes focus on the most processor friendly while we focus on the one that gives you the most power as a developer.

There are basicly 2 ways to work with the class :

1. with the EC - the event controller is a global class that way you can use one class to control all events did you see the example files lets just imagine this for a second imagine that you have a section on your site or your application on a lot of classes but there all related to each other when ever you leave that area you just want to kill all events(to avoid memory leaks) the easiest way to do it is by when you add an event grouping it up with a group name:

EC.add(btn, Event.ENTER_FRAME, loop, "group1");
EC.add(btn, MouseEvent.CLICK, onClick, "group1");
EC.add(btn, MouseEvent.ROLL_OVER, onOver, "group1");
EC.add(btn, MouseEvent.ROLL_OUT, onOut, "group1");

lets pretend we added this in a few classes and diffrent objects now when ever you want to kill all the events you can from any place in your application call
EC.remove("group1");

one more really cool feature is actually you can save the information returned when you remove events:
var data = EC.remove('group1');
enabling you to restart them again (this is an undocumented feature by the way :P)
then you can just restart it
EC.add(data);// and all the events will return


2. you can always create an LEC (local event controller) its the exact same thing only instead of being a global class its a more private scope so you can protect your creation from other areas of the site or create buckets for managing events. that's really the basics of it.

best way to figure it out is to give it a run on a real project and see what happens ;)

the advantages are : more control, easier to remove a lot of events at the same time, and its mainly used for monitoring and grouping.

other libraries have advantages as well mainly when it comes to improving performance as our class doesn't have the intention of helping performance but helping cut down the amount of typing more then anything else and making it easier to get things done faster and breaking with it the rules of encapsulation (that everything should be separated im not a fan of rules that make me type more) :)

Devon

unread,
Jul 3, 2012, 1:59:42 AM7/3/12
to eventco...@googlegroups.com
Sorry, I'm may not have been clear... I think I understand what was demonstrated in the examples and videos. However, I need to dispatch my own custom event dispatchEvent( new Event( "myEvent" ) ); because I'm not looking for a click or otherwise automatically dispatched event...

Currently, I'm using a singleton to broadcast events and to listen to events on... Given the following example, how can I accomplish the same using your class/library?

Let's say I have:
package com.name.connections
{
import com.name.events.EventSingleton; 

public class Connection
{
private var _evt:EventSingleton;
 
public function Connection()
{
_evt = EventSingleton.dispatcher;
_evt.dispatchEvent( new Event( "somethingHappen" ) );
}
}
}

Then I have:
package com.name.handlers
{
import com.name.events.EventSingleton; 

public class LoginHandler
{
private var _evt:EventSingleton;
 
public function LoginHandler()
{
_evt = EventSingleton.dispatcher;
_evt.addEventListener( "somethingHappen", doSomething );
}
}
 
 
 
 
 
 
 
 
 
 

Ben Fhala

unread,
Jul 3, 2012, 8:53:53 AM7/3/12
to eventco...@googlegroups.com
Ahh sorry i see what you mean now.  cool that doesn't mater you continue dispatching and even adding events the way you are in the class itself but as a user of the class you would never interact with it directly so in this case if you had a new connection you wouldn't call directly addEventListener but instead you would call  EC.add when you want to trigger an event.

in the back of the hood of the class it will call your built in addEventLIstener but before doing it it categorizes it and lists it out so its easier to sort through and monitor events.

that's really the big difference we aren't changing anything in the natural way events work all we are doing is hijacking the flow to add features and to monitor memory leaks.

so in your case if you are running a singleton you could do something like this if you wanted:

public function LoginHandler()
{

EC.add(EventSingleton.dispatcher, "somethingHappen", doSomething,'mygroup');
}


and you wouldn't change anything in the dispatcher itself that can stay the same.


Reply all
Reply to author
Forward
0 new messages