00:00
00:00

AS: AsBroadcaster

2,806 Views | 11 Replies
New Topic Respond to this Topic

AS: AsBroadcaster 2006-05-30 16:09:00


www.AS:Main.com

AsBroadcaster

Introduction: AsBroadcaster is something which is used to create your own events. For example, the onEnterFrame is an event that is called every time at the beginning of each frame, onMouseDown is called when the mouse is clicked, etc. With AsBroadcaster, you can create your own events for Flash.

How: AsBroadcaster is different to most other classes as it is not created like this:

var asb:AsBroadcaster = new AsBroadcaster();

Instead you must create a new object and then tell Flash to use that object as the broadcaster like so:

var asb:Object = new Object();
AsBroadcaster.initialize(asb);

Now Flash knows that you want to broadcast messages using this object as the broadcaster, simple enough right? Ok, now to send out these messages. I'm going to use a simple one as an example which will be called whenever the mouse is dragged held down, so we will do it like this:

var asb:Object = new Object();
var asb2:Object = new Object();
AsBroadcaster.initialize(asb);
asb2.onMouseDown = function() {
bla = setInterval(function () {
asb.broadcastMessage("onMouseDrag");
}, 1000/50); //Change 50 to your framerate
};
asb2.onMouseUp = function() {
clearInterval(bla);
};
Mouse.addListener(asb2);

Now the event onMouseDrag will be called while the mouse is down and stopped calling when it is released. I'm using an object called asb2 as the mouse listener. Ok, now we need it to actually work - so that we can use it. Add:

asb.addListener(_root);

This will make the event be sent to the _root timeline (you can change that to any movieclip) so now we can do this:

_root.onMouseDrag = function () {
trace("[X: "+_xmouse+" | Y: "+_ymouse+"]");
};

Now it should call the function specified whenever the onMouseDrag event is broadcast. Here is the full code, and here is a working example, working albeit the fact that I haven't done proper Z sorting yet but that's unrelated.


Sup, bitches :)

BBS Signature

Response to AS: AsBroadcaster 2006-05-30 16:13:09


Looks like a very useful class, nice tutorial.
I noticed in your example that the function doesnt stop being called when I stop moving the mouse, only when I release the button.

=P

SCGMD4 is on the way! @scgmd4

If a picture is worth a thousand words, a game is worth a play.

BBS Signature

Response to AS: AsBroadcaster 2006-05-30 16:17:05


At 5/30/06 04:09 PM, liaaaam wrote: and here is a working example.

nice :) i wish i was this good :(

you should make a "real" game though instead of just making tests and stuff

Response to AS: AsBroadcaster 2006-05-30 16:18:12


Wow, great tut, I actually learned something from that!

I also noticed sometimes the red and green look like part of the inner part of the cube, and not a face of the cube. Just wanted to point that out; it's not bad, but it isn't good. Nobody cares ;D


wew

Response to AS: AsBroadcaster 2006-05-30 16:20:41


At 5/30/06 04:13 PM, Shinki wrote: stuff

I know. Even though it's called onMouseDrag, it really should be called whileMouseHeld or something. I just wanted to keep the same sort of thing as onEnterFrame, etc.

At 5/30/06 04:17 PM, -reelbigcheese- wrote: you should make a "real" game though instead of just making tests and stuff

Oh shut up yer girl :(

At 5/30/06 04:18 PM, LordTrunks wrote: I also noticed sometimes the red and green look like part of the inner part of the cube, and not a face of the cube. Just wanted to point that out; it's not bad, but it isn't good. Nobody cares ;D

Yeah, I'm working on that now ^_^


Sup, bitches :)

BBS Signature

Response to AS: AsBroadcaster 2006-05-30 16:21:25


Been done a thousand times, but still good and unique. :)


BBS Signature

Response to AS: AsBroadcaster 2006-05-30 16:23:53


Really nice Liam, great job. ;)

btw. You still up for that game? :P im a sloooooooooow worker.

Response to AS: AsBroadcaster 2006-05-30 16:26:50


At 5/30/06 04:23 PM, Darkfire_Blaze wrote: btw. You still up for that game? :P im a sloooooooooow worker.

Yeah, whenever :)


Sup, bitches :)

BBS Signature

Response to AS: AsBroadcaster 2006-05-30 16:37:07


Wow, very nice, well done. I love it.


BBS Signature

Response to AS: AsBroadcaster 2006-05-30 16:46:26


Aha! That's very, very cool.
Where do you get these things from? Docs?

By the way, it'd be nice for you to go on MSN. I'd like to have a chat sometime

wtfbbqhax

Response to AS: AsBroadcaster 2006-05-30 16:50:51


At 5/30/06 04:46 PM, fwe wrote: Aha! That's very, very cool.
Where do you get these things from? Docs?

Yeah, and testing myself.. ><

By the way, it'd be nice for you to go on MSN. I'd like to have a chat sometime

I'll go on tomorrow, too late now :X


Sup, bitches :)

BBS Signature

Response to AS: AsBroadcaster 2006-06-02 05:54:38


Its a nice tut. I noticed that with an onMouseDown, it just sees if its down in the .swf file's area. This checks to see if its inside or outside it.

I might try it out now :)

BBS Signature