Be a Supporter!

Curious about classes

  • 278 Views
  • 4 Replies
New Topic Respond to this Topic
wyslet
wyslet
  • Member since: Apr. 1, 2007
  • Offline.
Forum Stats
Member
Level 09
Game Developer
Curious about classes 2012-10-16 02:32:25 Reply

So 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?

ProfessorFlash
ProfessorFlash
  • Member since: Oct. 6, 2007
  • Offline.
Forum Stats
Member
Level 32
Programmer
Response to Curious about classes 2012-10-16 03:58:04 Reply

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.

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Curious about classes 2012-10-16 06:01:43 Reply

As3 cannot serialize DisplayObjects.

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Curious about classes 2012-10-16 06:29:26 Reply

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

wyslet
wyslet
  • Member since: Apr. 1, 2007
  • Offline.
Forum Stats
Member
Level 09
Game Developer
Response to Curious about classes 2012-10-16 18:47:25 Reply

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!