Main menu on game - actionscript-3

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.

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.

Load the swf output from Menu.fla and keep a check on the progressEvent from loader. Don't show the game screen until Menu.swf is completely loaded and initialized.
Some more details wrt comment from OP:
You can you http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html#load%28%29 to load external swfs. init Event would mark that the swf's actionscript has started executing. OTOH, complete event would tell that all the swf bytes have been loaded.

Related

AS3 - replacing / taking over base AS function

I have following scenario:
I load many external swf files (they are at same domain) dynamically inside my AS3 loader.
All of them using navigateToURL (AS3) or getURL (AS2) on some buttons, that redirects to currently no more existing old domain.
Is it possible to replace (take over) navigateToURL and getURL base AS functions to change redirect link to up to date one or at least block loaded swf from opening urls?
No. You can extend classes, and implement your own override for methods/properties, but the previously compiled swf would need to point to your new class (which it won't).
You could try catching the error thrown (perhaps with UncaughtErrorEvent) and judiciously interpret the intended URL and dispatch the appropriate commands. The ideal would still be to just recompile the loaded SWF after running a search-and-replace for the deprecated method.

addchild from externally loaded swf in Air project

I am working on an Air app for iOS and looking for a way to load an external swf and then add/remove the movieclips in that library to the main stage.
Normally, I can use an addchild routine in the document class of the external swf which I can access from the main document class. But since document classes in externally loaded swfs are not allowed in Air deployment, I can't use this method.
Each external swf will contain up to 10 separate movieclips and there are over 25 external swf's I want to load in/remove from the main stage, all containing unique artwork/animation.
Can anyone please suggest a way to do this?
THANKS!
matt
I had same problem i also had around 10 different external swfs with code. So the easiest way for me was to compile every file to swc and included them after in project.

How to debug/step through external/loaded swf - FlashProfessional?

(Flash Professional / AS3)
I have a main fla file that loads a game (with a Loader) and adds it to the stage (addChild(myLoader)). Is there a way to step through/debug the loaded swf? If so, how? My game.swf breakpoints aren't hitting.
Did you debug (Control > Debug Movie) both files?
You need to debug both Main and Game to be able to get breakpoints in the loaded SWF to work. When you Debug a SWF, extra information is added to the file. If you just publish the file there will not be any debug info.
You could try using MonsterDebugger.

AS3: How to dynamically load movieclip from library without exporting in frame 1?

I have some fairly large movieclips in the library which need to be dynamically loaded at runtime. I don't want to export them all in frame 1, because that would slow down initial loading of the movie.
I tried putting an instance of each of these clips later in the timeline where they wouldn't normally be encountered. When I then tried to load one from the library dynamically, I was able to successfully get an instance of the movieclip, but its currentFrame property was 0 and I couldn't see anything on the stage. As soon as I enabled "Export in frame 1", it worked properly.
Does this old trick of putting an instance on the timeline somewhere no longer work in AS3?
I have had similar issues with large library assets and to solve my issue I would always just put the assets into separate swf's and load the external swf file when I needed it.
Check out the Loader class 'content' property - http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Loader.html#content
The only downfall to this is managing the assets in separate files.
I hope this helps.

Loading a SWF into an ActionScript 3 project (Flex Builder)

We're developing a small Flash gamelet for an European client of ours, who require us to develop our Flash game in such fashion that they can load our SWF game into their ActionScript 3 project, dynamically.
Basically they have a console that will load many other Flash games, amongst our own, depending on which button the player presses on a "Choose Your Game" screen.
Basically, we have a FLA project that we're authoring in Flash Professional CS4 and everything is basically a straightforward Flash game. When we test the game via Ctrl+Enter or run the compiled SWF file by double clicking it, all works well, the game executes perfectly and everybody is a happy bunny.
What we need to grasp is loading our SWF into our clients AS3 project, which is basically an external ActionScript 3 project created in Flex Builder 3. The client posted us the following code to load the SWF:
var myGame:FunkyChickenGame = new FunkyChickenGame();
addChild(myGame);
...which gets executed in the ActionScript 3 application constructor of the clients app, or perhaps an event handler for a button pressed on the "Choose Your Game" screen.
We tried creating a blank AS3 project in Flex Builder and tried loading the SWF as per my snippet above. All our traces within the external SWF's document class are showing up as expected in the Flex Builder console view, so the code is running perfectly.
The problem we're experiencing is that despite calling addChild(myGame)...we're not seeing any graphics, just the default background color of the encapsulating AS3 project.
Note however, when we run the SWF by double clicking the Game.swf file in Windows, it all executes perfectly, the game works without flaw and glitches.
Any help on this topic would be highly appreciated. Thank you in advance.
What you need to use is an instance of the Loader class, like so:
var loader:Loader = new Loader();
// you'll need to write a method named onLoaded to capture the COMPLETE event
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
loader.load(new URLRequest("game.swf"));
addChild(loader);
Creating an instance of a class is as wage as it can get. Your client has a funny way of posting references.
However FunkyChickenGame may be a class created by the client that can launch your game. Maybe the games are embedded in their flash app, but that would mean long loading time. If indeed many games are "loaded" this way.
My advice would be that you don't use stage, root or whatever properties that could link to the main app instead your game, and leave the client to decide how he would like to load it.