Search code examples
actionscript-3flashflash-cs6

Main menu on game


I have created a menu for my game with buttons and whatnot as a separate .fla file named Menu. My actual game is another .fla file called Game.fla. I was wondering what the best way would be of loading this menu before the game plays?

Thanks.


Solution

  • I would suggest that you create a .swc with your Menu.fla, and then just add that .swc to your Game.fla

    If you are using CS6, make sure that you are setting linkage for any MovieClips you want to create instances of in your code.

    In the actionscript settings on the library path tab, you can add a .swc that will be included into your .swf when compiling.

    In your code, you can now create an instance and add to the display list :

    // Assuming MainMenu was a movieclip with linkage set in your .swc 
    var mainMenu:MainMenu = new MainMenu;
    addChild(mainMenu);
    

    I should note that this does not load the .swc at runtime, it includes the .swc to your .swf at compile time. I would recommend this method over loading a .swf in most cases. Cases where I might not, is if there was a large amount of content that wasn't needed all at once. That would allow you to minimize the amount of memory you were using and reduce the .swf size of your main .swf so it loads quicker.

    Anytime you are loading .swf's in at runtime you are adding another layer of complexity, so I'd not recommend it unless you do have a good reason to do so. From what you have described, this doesn't sound like a situation where I'd load an external .swf at runtime.