Sign in to follow this  
Funkymunky

[web] Actionscript: interaction between classes

Recommended Posts

Is it possible to have interactions between classes in actionscript? Say I have one character and I want him to punch the other character. Both are movie clips that are being controlled by independant classes. So I want the first characters class to tell the second one "i punched you, react." Furthermore I then want the first class to tell a third score-keeping class to change the health meters. How would I go about doing this type of thing?

Share this post


Link to post
Share on other sites
hmmm, here's what i'm thinking. Right now, I set up my updates like this:


onEnterFrame = function()
{
fighter.Update();
baddie.Update();
}


fighter and baddie are two different classes. Maybe i should change the onEnterFrame to do something like this:


onEnterFrame = function()
{
fighter.Update();
baddie.Update();

var fState:String = fighter.getState();
var bState:String = baddie.getState();

var fReaction:String = intermediary.CheckFighter(fState);
var bReaction:String = intermediary.CheckBaddie(bState);

fighter.React(fReaction);
baddie.React(bReaction);
}


in this, intermediary is a new class which will make decisions based on the state returned from the first two classes. It then issues a reaction response, which is in turn passed to each class.

This seems really convoluted and over-complicated. Is this really the best solution?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this