Forum Topic: AS: AsBroadcaster

(1,337 views • 12 replies)

This topic is 1 page long.

<< < > >>
None

liaaaam

Reply To Post Reply & Quote

Posted at: 5/30/06 04:09 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

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.


None

Shinki

Reply To Post Reply & Quote

Posted at: 5/30/06 04:13 PM

Shinki DARK LEVEL 10

Sign-Up: 02/14/05

Posts: 1,571

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

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

BBS Signature

None

reelbigcheese

Reply To Post Reply & Quote

Posted at: 5/30/06 04:17 PM

reelbigcheese LIGHT LEVEL 18

Sign-Up: 08/12/05

Posts: 2,162

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


None

Trunks

Reply To Post Reply & Quote

Posted at: 5/30/06 04:18 PM

Trunks DARK LEVEL 22

Sign-Up: 07/31/05

Posts: 4,167

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

'05 users for the win :3

BBS Signature

None

liaaaam

Reply To Post Reply & Quote

Posted at: 5/30/06 04:20 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

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 ^_^


None

Toast

Reply To Post Reply & Quote

Posted at: 5/30/06 04:21 PM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,919

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


None

Blaze

Reply To Post Reply & Quote

Posted at: 5/30/06 04:23 PM

Blaze LIGHT LEVEL 22

Sign-Up: 08/04/05

Posts: 6,989

Really nice Liam, great job. ;)

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


None

liaaaam

Reply To Post Reply & Quote

Posted at: 5/30/06 04:26 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

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

Yeah, whenever :)


Happy

Cema

Reply To Post Reply & Quote

Posted at: 5/30/06 04:37 PM

Cema LIGHT LEVEL 13

Sign-Up: 07/28/05

Posts: 1,941

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

BBS Signature

None

fwe

Reply To Post Reply & Quote

Posted at: 5/30/06 04:46 PM

fwe DARK LEVEL 08

Sign-Up: 07/24/03

Posts: 3,361

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


None

liaaaam

Reply To Post Reply & Quote

Posted at: 5/30/06 04:50 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

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


Happy

Depredation

Reply To Post Reply & Quote

Posted at: 6/2/06 05:54 AM

Depredation LIGHT LEVEL 17

Sign-Up: 09/05/05

Posts: 4,782

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

None

BritishMoose

Reply To Post Reply & Quote

Posted at: 6/2/06 06:13 AM

BritishMoose NEUTRAL LEVEL 15

Sign-Up: 10/18/03

Posts: 2,954

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

ZOMG but we're meant to make a game!? Hussy :'(

Nice tut, it was nicely explained ^^

Never forget...

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 09:32 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!