Hi all,
Im kinda new to the whole event dispatching and listening way of doing
things that the v2 components have introduced me to and would like some
advice on how to go about coding this situation:
Suppose i have a game which is represented by a class cMyGame and within
there i have have my main menu system called cMyMenu. Some code:
class cMyGame
{
private var myMenu;
function cMyGame()
{
myMenu = new cMyMenu();
}
}
class cMyMenu
{
function cMyMenu()
{
{
}
Okay now suppose that inside my menu class i have a load of button
componants to represent the different menu options. When a user clicks one
of the menu options i would like the game to then destroy the main menu (or
atleast hide it) and then go to the option that the user clicked on.
What i would like to know if how the menu system should tell the cMyGame
what to do if the user clicked a button. As i see it there are a coupple of
ways, i could pass a reference to the cMyGame into the constructor then just
call it like so:
class cMyMenu
{
private var myParent:cMyGame;
function cMyMenu(parent:cMyGame)
{
myParent = parent;
{
function onMenuOption1Released()
{
myParent.doSomething();
}
}
Or the alternative is to use events and listeners so that the game can
listen to events fired by the menu class.
I know this seems like a very basic problem but it is at the core of my
fundemental understanding of how you should scope your project. So if anyone
could advise me on the best programming practice i should be using it would
be greatly appreciated, thanks :)
Mike
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com