I'm adjusting my game to use the model-view-controller pattern. I was already fairly close: all I had to do was move a couple of classes into a separate package for the controller, plus do some separation of authority.

But this means that I have clickable things in one class (the main application MXML or something I include in that), but the click events are handled in a different class. I naively tried calling a static method in the controller class, but the compiler objected. It seems as if the event handler needs to be in the view class (at least, when coding components in MXML).

So I need to have an event handler in my MXML <script> section, which will get some sort of information about the component that originated the event and call the appropriate handler in the controller and/or model class.

Right?

Or is there a better way that I'm not seeing. What I don't like about my current approach is, it looks like I need a separate click handler for every clickable item in the game.

Relevant code:
<s:a href="." click="gotoMainMenu()">(magic word)</s:a>

  <fx:Script >
    <![CDATA[
  ...
      protected function gotoMainMenu():void
      {
          myController.mainMenu();
      }
  ...

   ]]>
 </fx:Script>

Reply via email to