Monster Racer Rush
Select between 5 monster racers, upgrade your monster skill and win the competition!
4.18 / 5.00 3,534 ViewsBuild and Base
Build most powerful forces, unleash hordes of monster and control your soldiers!
3.80 / 5.00 4,200 ViewsSo I am trying to understand the way classes and oop work.
Right now, I have a "Main.as" and a "Circle.as." I want the user to be able to move the Circle using the keyboard. Nothing serious, and I have created this script without using separate classes before, but I want to do it right.
My question is, which code goes in which file?
For example:
Do I place the addEventListener(keyBoardEvent.KEY_DOWN) in the Circle.as or the Main.as, or do I put the listener in the Main.as and hold the variables in the Circle.as.
If the Listener does go in the Circle.as, how do I call those functions? That is what I am trying to do now, and I can use the trace function to access all the methods except the ones that are accessed by the listener.
Any tips? Have I confused myself too much for one day?
Handle the logic in the 'container' classes. If you add the circle to main, then the main contains circle thus main handles the logic behind the circle. Applying this to your example, you would handle key input in the main. The circle would have information about itself, like speed, rotation, direction etc., and actions like moving it would be handled in the main.
You can solve pretty much any problem you may have with AS3 by consulting the AS3 Language reference.
At 10/16/12 06:01 AM, milchreis wrote: As3 cannot serialize DisplayObjects.
fail: wrong thread, sorry.
At 10/16/12 02:32 AM, wyslet wrote: do I put the listener in the Main.as and hold the variables in the Circle.as.
this
At 10/16/12 03:58 AM, ProfessorFlash wrote: Handle the logic in the 'container' classes. If you add the circle to main, then the main contains circle thus main handles the logic behind the circle. Applying this to your example, you would handle key input in the main. The circle would have information about itself, like speed, rotation, direction etc., and actions like moving it would be handled in the main.
Awesome, thank you. That's what I needed to hear!
And Chris, its good to know that DisplayObjects cannot be serialized ;) haha and thank you so much for the answer!