Search code examples
flashactionscript-3actionscriptflash-cs4

advantages and disadvantages to having multiple loops flash


What are the advantages and disadvantages of having just one main loop and having a main class control individual objects on your stage, in oppose to having each individual object have its own loop and giving it the responsibilities of doing what ever it has to do on its own. What are consider best practices.


Solution

  • I don't know that "loop" is necessarily the right term here.

    If you're talking about having a single DocumentClass that controls everything versus having a lot of classes (ie most of your major visual elements have their own classes with their own internal logic) then it is to some degree a matter of personal preference. However, generally speaking it's probably a good idea to separate your concerns as much as possible.

    If you have a main document with, let's say, two characters - the player and an enemy monster - then you don't want to write all of your code on the document. Instead, you want the player and the monster to each have their own internal code. That way it's easy to later add another monster, for instance - does that make sense?

    Rather than writing out all of the complex logic for each monster twice, you simply create a Monster class and then you know that it'll always react the same way, even if you put a million on the stage. And you only have to write the code once.

    Does that make sense? It's kind of a vague question, but yeah - if you want to take a "programmer's" approach it's always best to write the least amount of code possible. In the case of Flash architecture, that frequently means letting your code live where it can be most efficiently reused.

    I hope that helpS!