views:

144

answers:

2

I am All Programmer when it comes to anything including flash. I got into making games not to long ago and some people use frames to navigate from the main menu to the game screen and so on (which I have no idea how to do). and some people encapsulate the game inside of a class and call it from the document class and add and remove it when please.

I am just curious of what is the best practices when it comes to this and what is most beneficial. What do the pros do.

+1  A: 

If you start with Flash, just the IDE and then learn how to code, navigating through frames makes sense as it's dead easy to understand/implement.

The only advantage I can think of is that objects are always there, so when you're going from one frame to another, once the objects are instantiated, they'll be there for you, so no need to remove everything, add everything again.

I'm guessing pros like Keith Peters code there views and menus 100%. Once you make your nice little game engine ( with menus and screens) ready to be reused (Asobu), the timeline seems a bit pointless for switching views. The PushButtonEngine looks great from this perspective.

If you're working with a designer, and he/she is designing the screens and the timeline navigation makes more sense for him/her while prototyping, I'm guessing there is a middle ground. As long as each screen is a MovieClip on it's own, inside the main timeline, you can set a Class for each screen MovieClip and carry on from there. If you need something to declare stage instances for you, I wrote a tiny extension that could give hand with that. Then you can carry on with the logic in your preffered IDE.

My guess is for quick additive button bashing short indy games the timeline will do just fine. If you're planning to reuse a basic engine and make more complex games, on the long run, actionscript will prove the right decision. Basic rule of thumb: Don't over complicate things without reason.

George Profenza
My code isnt that complex, but I see what your saying. I might as well stick with whats best for me. Coding. thanks
numerical25
Yup, there are many ways of doing the same thing. Do whatever makes you feel comfortable and have fun. Glad I could help :)
George Profenza
+1  A: 

Using the timeline is generally regarded as not best practise. You will tend to find designers who start programming tend to use the timeline a lot as thats what they are used to. Also programmers who started off with AS1 or AS2 tend to have bad habbits. If something is worth doing its worth doing properly.

The problem with using the timeline is managing your variable states. Any variables that are declared in a frame will be lost if you then move to another frame (except for the first frame). To demonstrate imagine this basic example:

On the first frame there is an options button that when clicked goes to another frame "options". This options frame has a check button and also declares another object. It also has a button to return to the main menu. This is what it looks like when the compiler has generated it into code:

package DemoAvoid_fla
{
    import fl.controls.*;
    import flash.display.*;
    import flash.events.*;

    dynamic public class MainTimeline extends MovieClip
    {
        public var btnOptions:SimpleButton;
        public var chkHints:CheckBox;
        public var myWorld:Object;
        public var btnReturnToMainMenu:SimpleButton;
        public var declareSomeInstace:Object;

        public function MainTimeline()
        {
            addFrameScript(0, this.frame1, 1, this.frame2);
            return;
        }// end function

        public function onOptionsClick(event:MouseEvent) : void
        {
            gotoAndStop("options");
            return;
        }// end function

        function frame1()
        {
            stop();
            this.myWorld = new Object();
            this.btnOptions.addEventListener(MouseEvent.CLICK, this.onOptionsClick);
            return;
        }// end function

        public function onReturnToMainMenu(event:Event) : void
        {
            gotoAndStop("mainMenu");
            return;
        }// end function

        function frame2()
        {
            stop();
            this.chkHints.addEventListener(Event.CHANGE, this.onHintsChange);
            this.btnReturnToMainMenu.addEventListene(MouseEvent.CLICK,this.onReturnToMainMenu);
            this.declareSomeInstace = new Object();
            return;
        }// end function

        public function onHintsChange(event:Event) : void
        {
            var _loc_2:* = event.target.selected;
            trace(_loc_2);
            return;
        }// end function

    }
}

Now this is where the problem lies. If you were to navigate to the options page then return to the main menu you would end up resetting your variable state as you now create a new instance of my world (and memory usuage goes up as the garbage collector won't be instant). You have now also lost your instance in your options page.

My coding style for menus is to create each screen as a movieclip. Then place each movieclip on the first frame but on different layers. I then hide/show the layer I want. Its also easy to control from external classes and just as quick to design and avoids any of the pitfalls that I mentioned :)

Allan
Well I feel more relieved. I didnt intend on using the timeLine anyhow. But still the biggest challenge programming is managing all those display objects. not only do you have to manually remove them all. but you must also make sure all event listeners are destroy as well. I just started actionscript, so I am learning everything. but still trying to get into habit of that. and the best practices for grouping display objects to be destroy along with listeners
numerical25
It's pretty interesting how Flash, which has its roots firmly in the frame metaphor after all, has become little more than a vessel for ActionScript to speak to graphical objects. (If that). Pretty much all AS devs I know, myself included, try to spend as little time as possible in the Flash IDE and will rather work with pure ActionScript projects and import graphic assets at runtime.Just a fleeting bemusement. :)
Martin
It certainly is :). I am now finding I am avoiding even using Adobe's compiler and writing AS3 in another language.
Allan