PDA

View Full Version : new to class workflow, how do you manage files?



natronp
October 10th, 2008, 09:35 AM
I'm relatively new to AS3 and a class-based workflow.

What's the best way to handle .as files as relates to the document class?

i.e.- if i have:

1. reusable preload code
2. code to handle papervision 3d stuff
3. code to handle site functions involving movieclip placement, etc.
4. form validation/user data code
5. navigation code
6. full screen, reposition clips code

and i would like to separate those as much as possible, what is best practice? To put items 1 - 6 in their own .as files and do includes in my document class? Items 1-7 will relate to clips/display objects that will exist in my main .fla (i'll only have one .swf file if i can help it).

Or, is there a better way to utilize / manage external code that my noobness prevents me from grasping?

thanks for input people!

jwopitz
October 10th, 2008, 01:52 PM
I generally think of things with a Model-View-Controller mindset. So rather than thinking of all these tasks you want to perform, I would think higher-level and try to imagine things as objects. After all, OOP is where the true power of any OO languages is harnessed. So think of it this way:

- rather than preloader logic, have a preloader class that is generic enough so that you can reuse it regardless of what is loading (be it the main SWF, or rendering a scene or whatever). This would be a View component (as in mVc)
- handling your pv3d scene construction is more like saying, hey, give me the data for this scene, parse it, massage it, feed it, whatever and then store it somewhere. So you are probably looking at some kind of command-type class that fetches the necessary data to construct a scene, once done so, store it somewhere on a model so that view-type classes can fetch that data.
- this sounds like a view-class. Depending on if you see this as building a one-time-use view vs. a reusable component will drive the API.
- here are two of many schools of thought on validation and user input. a) have the view class handle the validation before handing off to a command class or b) just hand off everything to the command class and have it handle the validation. There is no wrong way of doing this. If you have items on a form for instance, and those items have no dependencies on each other, then you could use scenario b. However if you had to do something like reenter your password to see that they match, then scenario a is the best bet.
- view class (depending on complexity of navigation, you might just have the view handle its own state logic, or you could hand off to a command, who then modifies state on a model which updates the view).
- yet another view class.

This may sound overwhelming, but trust me, once you get into the OO mind set, you will never look back. Do some research on MVC, Cairngorm (just so you can see the MVC structure working in terms of events and as3, also forget delegates for now, Cairngorm is really for Flex) and also read up on some basic OO principles.

Hope that helps.

natronp
October 10th, 2008, 02:10 PM
thanks for the advice mate!

sekasi
October 10th, 2008, 07:38 PM
(ultimately however, you don't want to stay too focused on just the MVC pattern. Although MVC is more a 'hierarchy' than a design pattern, it pays off to think outside the mvc box at times. Look into the controller pattern, composite pattern as well as the memento pattern. They are all really useful and generic enough to be applied to almost any application at some point)