class communication between 2 classes

By taonuts | Jul 11, 2009

actionscript3

hi everyone, so i have an "Engine" class that is the backbone of the program and i want all my keyboard inputs in a separate class named "Controls"

ActionScript Code:
public function Engine() {                         //addChild(controls);                     addEventListener(Event.ENTER_FRAME,moveMap);                         }         public function moveMap(event:Event) {             if(controls.left){                 trace(“LEFT!”);             }             else if(controls.right == true){                 trace(“RIGHT!”);             }         };     };
ActionScript Code:
public function Controls() {                         trace(“OK!?”);             addEventListener(KeyboardEvent.KEY_DOWN,keyDownListener);             addEventListener(KeyboardEvent.KEY_UP,keyUpListener);                                         }                          //Inputs                 public function keyDownListener(evt:KeyboardEvent):void {             switch (evt.keyCode) {                 case 13:                     enterReturn=true;                     break;                 case 87:                     trace(“UIP!”);                     up=true;                     break;                 case 83:                     down=true;                     break;                 case 65:                     left=true;                     break;                 case 68:                     right=true;                     break;                 case 69:                     showDisplay=true;                     break;             }         };         public function keyUpListener(evt:KeyboardEvent):void {             switch (evt.keyCode) {                 //case 13:                     //enterReturn=false;                     //break;                 case 87:                     up=false;                     break;                 case 83:                     down=false;                     break;                 case 65:                     left=false;                     break;                 case 68:                     right=false;                     break;                 case 69:                     showDisplay=false;                     break;             };         };     };

is it the addEventListener in the controls class? do i need to add it somewhere specific? How does the engine class know if the keys have been pressed in the controls class?
I hope this makes sense, I have tried everything I can think of and cant figure it out. I hope my newbie question makes someone laugh
Thank you so much for looking at my problem:confused:

actionscript3

Please reply at our Forum

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

© 2007 ActionScript 3.0