MGAS3FD 2: The Beginning


You have arrived at the second part of Making Games in ActionScript 3 using FlashDevelop.

Last time we got stuff setup. Not all that amusing really, just a tiny bit more setting up to go before we can get some stuff on the screen.

Your first project

Time to get your feet wet.
Go Project -> New Project…
What we want is an “AS3 Project”, normally the Preloader version is the way to go, but for clarity we’ll use the plain one this time around.

Set the name to whatever you please, I chose SuperGame, for location, use whatever seems suitable.

You can set a package name if you want too, this is just to keep your code separated from other people’s code if you ever use it in your games. The convention here is to use reverse domain naming for packages. So, by that logic I use com.grapefrukt.tutorial.supergame
You don’t need to own the domain or anything, it’s just to keep things separated. You can read more about this in the excellent ActionScript 3.0 Cookbook, but it’s not really that important for now.

That should be it for that dialog. Now, FlashDevelop will create a few template files for you.

As previously mentioned, the package structure is just a way to organize your code, and you can name it whatever you please. However, to enforce a good package structure Flash requires the files to be in folders corresponding to the package naming. So, with the folder src being our source “root”, and com.grapefrukt.tutorial.supergame my package structure, you can see the folders created to accommodate that. The compiler won’t be happy if you don’t put your code in the proper folders.

That’s enough about packages for now (and hopefully for the rest of this tutorial, they’re pretty boring)

Let’s move on to the code.

The file we’re interested in is the one called Main.as, open up that file using the Project panel.

For some reason FlashDevelop will include some code to make sure everything is loaded before running, but we can strip that out for now. Remove the whole init() function and the contents of the Main()

What you should be left with is something that looks like this (although your package may differ)

package com.grapefrukt.tutorial.supergame {

	import flash.display.Sprite;

	public class Main extends Sprite {

		public function Main():void {

		}

	}

}

This is about as bare-bones as it gets, Main will be what is normally called your document class. It needs to extend Sprite (there are a few other options aswell, but we’ll get to those later), this is one of the basic Display classes available in Flash.

Hello trace()

The trace() function is one of your best friends as a flash developer. Also, we need to make sure the debugging stuff works, so it’s a great place to start.

public function Main():void {
	trace("Hello world!");
}

Once you’ve gotten that little line into your Main() method, check that FlashDevelop is set to compile in Debug mode.
Also, make sure you’ve got your Output panel up, it’s in View -> Output Panel

If you got the External flash player, this is the time to set it up, go into: Project -> Properties… and set the Test movie-dropdown to “Play in external player”. This step isn’t required, you can stick with the default if you like that better.

Once that’s done, click the cute little arrow next to the debug/release field (you can also press F5 if you’re feeling “pro”)

If all goes well there should be a bit of chugging as the largish java driven compiler awakens from it’s slumber and then a loud explosion of impressiveness as it actually compiles your code.

A new tab/window should appear with your as of yet humble Flash game in it, it will be hard to tell if it’s working since we’re not doing any graphics yet, but if everything went as expected the Output panel should hold what we’re looking for:

[there's some more stuff here, but i cut it for brevity]
Build succeeded
Done (0)
[Capturing traces with FDB]
Hello world!

If the compile seemed to work nicely but you didn’t get that last “Hello world!”-line, you likely only have the Release player installed. It does (unsurprisingly) not bother with sending debug events to the debugger inside FlashDevelop. If so, go back to the first installment of this series and grab the link from there.

That’s it for the second part, next time we’ll be making some graphics appear!

If you want to go and do some reading on your own I really recommend the Flash documentation, it’s among the best docs I’ve ever seen.

As usual, any and all comments/questions are very welcome. Either as comments here, or if you’re so inclined  tweet me!

You can find part three right here.

Posted in code, Making Games in Actionscript 3.0, Tutorials |

52 Responses to MGAS3FD 2: The Beginning

  1. Moar moar!!1111

  2. it’s -> its

  3. You didn’t mention that you may need to point FlashDeveloper to the SDK first… or is that nessecary? It wasked me for it, but I figured it out.

  4. I don´t get it. When I press F5 it always says “Compiler Configuration required.”

  5. ah now I got it working

  6. Good so far!!! Oh and James I think he said in Part 1?

  7. Please, need help

    I dont get the “Hello World” message in Outbox.. you said this:
    “If so, go back to the first installment of this series and grab the link from there.”

    But Im not sure which link to grab

  8. Click Flash Player 10 which will bring you down to a bunch of text. At the bottom of that, click Download the Adobe Flash Player 10 Update for Windows and Macintosh (ZIP, 44 MB). After that’s downloaded, extract it. Then go into the Debug folder. Run FlashPlayer.exe. Run your game again and the message should appear. That’s what fixed it for me.

  9. So, I followed what Anon said, the message still didn’t appear. IS it very important that the message appears?

  10. It’s not the end of the world if you’re not getting the traces, it will however make things alot harder since you won’t be getting any runtime errors when things go wrong (and they will) so it’s going to be a lot harder to track down errors.
    If you’re positive you’ve installed the debug player the only thing i can think of is that the debug player uses sockets to communicate with flashdevelop, so it is possible that an overzealous firewall might block it too.

  11. Traces are meant for making tracking errors much easier, if thats how I’m receiving it, right? The only way I can fix it is either checking the firewall or making sure I really do have the right debugger, am I correct?

  12. yep. it should be fairly easy to see if you have the debug player.
    open a swf in the player and right click the stage. if you have the two options “Show redraw regions” and “Debugger” in the list, it’s the debug player.

  13. Hey all,

    Instead of “Hello world!” at the end of the outbox, I’m getting “Application not found.” What application is it referring to? Thanks in advance!

  14. Never mind, I cleared it up. Apparently I had to have the debug flash player running in a separate window when I hit F5

  15. How do i make FlashDevelop open the debugger instead of the regular Flash player? I renamed the debugger flash player and switched them in the adobe flash cs4 folder and it works, but I don’t think that’s right… Thanks for your time!

  16. @another person

    It could be possible that the .swf files aren’t being associated with the debugger. Make sure the debugger is associated with the .swf files.

  17. If you explicitly download the flash debug player (flashplayer_10_sa_debug.exe), you can copy it anywhere convenient and point FlashDevelop at it under:

    Tools->Program Settings->Flash Viewer->External Player Path

    Then, make sure you specify that the project should use the external player:

    Project->Properties->Test Movie should be “Play in external player”

  18. This was the answer that helped me out.. Thanks Anonymous fellow

    Anonymous
    February 23, 2010 at 06:22
    If you explicitly download the flash debug player (flashplayer_10_sa_debug.exe), you can copy it anywhere convenient and point FlashDevelop at it under:

    Tools->Program Settings->Flash Viewer->External Player Path

    Then, make sure you specify that the project should use the external player:

    Project->Properties->Test Movie should be “Play in external player”

  19. Ok, I followed everything exactly, but the text doesn’t show up in my movie. What am I doing wrong?

  20. it won’t show up *in* your movie, rather it’ll be in flashdevelops output window .

  21. Make sure .swf’s are set to be opened with debugger by default

  22. Where is part 3 of this tutorial!? -jk

  23. What do I need to do I am getting this message: Exception: Could not locate lib\mxmlc.jar in Flex SDK. Please set the correct path to the Flex SDK in AS3Context plugin settings.

  24. but I can locate it myself

  25. You need to set the location of your SDK as the last part of the first tutorial shows: https://prototyprally.com/making-games-in-actionscript-3-using-flashdevelop-part-1-the-setup/

  26. I have done that but it still can`t find it

  27. You should point it to the folder that has the subfolders: ant, asdoc, bin, frameworks, lib, runtimes, samples and templates.

    My guess is you’re either one step too high or low in the hierarchy.

  28. it worked, but i dont get the hello world! message in the output

  29. I have an old PC, I think I should wait until I get a new one…

  30. it is wery lagging

  31. *very

  32. I have been follow everything from the part 1 and this part of the tutorial up when I try to debug the trace code.

    I got the following error when trying to compile:

    Running process: C:\Program Files\FlashDevelop\Tools\fdbuild\fdbuild.exe “C:\Users\acer\Documents\FlashDevelop Projects\Test Project\Test Project.as3proj” -ipc 9b473e7a-26d3-4c93-8d5d-4c3601e790cd -compiler “C:\Flex SDK” -library “C:\Program Files\FlashDevelop\Library”
    Using the Flex Compiler Shell.
    Building Test Project
    mxmlc -load-config+=obj\TestProjectConfig.xml -debug=true -incremental=true -benchmark=false -o obj\TestProject634074407960057930
    INITIALIZING: Adobe Flex Compiler SHell (fcsh)
    Starting new compile.
    Loading configuration file C:\Flex SDK\frameworks\flex-config.xml
    Loading configuration file C:\Users\acer\Documents\FlashDevelop Projects\Test Project\obj\TestProjectConfig.xml
    obj\TestProject634074407960057930 (937 bytes)
    C:\Users\acer\Documents\FlashDevelop Projects\Test Project\src\Main.as: Warning: This compilation unit did not have a factoryClass specified in Frame metadata to load the configured runtime shared libraries. To compile without runtime shared libraries either set the -static-link-runtime-shared-libraries option to true or remove the -runtime-shared-libraries option.
    Build halted with errors (fcsh).
    (fcsh)
    Done (1)

    I am not sure what went wrong as I follow this tutorial exactly as it is… Any help is appreciated…

  33. You may want to specify that FlashDevelop uses Flash Player 9. I tried using 10 for quite a while before I figured out why my debug output wasn’t showing up. Otherwise, great tutorial!

  34. FlashDevelop will use whatever player you have installed. So, you likely had the “release” version of the flash 10 player, but then got the debug player for flash 9.

    I’ve been doing flash player ten since the first betas.

  35. I also have a problem; when I try to run the code, I get the following in the Output box:

    Error: a target file must be specified
    Use ‘mxmlc -help’ for information about using the command line.
    Build halted with errors (fcsh).

    What does it mean and how do I fix it?

  • Seems I somehow saved the project in a different place than the folders it creates. Moved them together, and it ran. Thanks.

  • What I found surprising is that instead of using external player, I used open popup and the message Hello world! appeared at last. But now it dawns on me I could have tried that months ago. Hey grapefrukt! I still gotta thank you for the tutorial here!

  • if you can not trace to the output window:
    according to the flex docs (http://livedocs.adobe.com/flex/3/html/help.html?content=logging_04.html)
    there is a debugger flash player installed in the location: Flex SDK: install_dir/runtimes/player/os_version/
    I used that one and it the above tutorial worked for me.

  • My trace isn’t showing up in the output window, and every time I try to download the LATEST VERSION from the Adobe website, when I try installing it, it states that I’m not installing the latest version and that I should go to the Adobe site and download the latest version. STUPID! God I’m so pissed right now.

  • Got it! Just had to uninstall previous version of Flash from command prompt using /clean argument.

  • So, Anon has the most likely solution: I have CS4 and I feel the problem is that it opens Flash Player 7….for no apparent reason. However, after opening the 44 MB Zip file and the debug, it works, but only for a few days…so I have to constantly open it…

    If I find a workaround, I’ll post it!

  • I get an information message saying “In order to build this project, you must mark the AS or MXML entry point as “Always Compile” in the project tree.”
    How do I get to the project tree?

  • How do you fix the “Compiler Configuration required.” after pressing F5??

  • Build succeeded
    Done (0)
    [Capturing traces with FDB]
    No application is associated with the specified file for this operation

    Please help?

  • I got it, it’s all good downloaded the adboe flash player projector again

  • What? when I do the debug thing it asks if I want this AS3 context thing, if I say yes it opens and nothing happens, if I say no nothing happens. And I can’t find the ‘Hello world’ thing in the output box. Help?

  • Never mind. But the Hello World part doesn’t come up, and I did download everything needed.

  • (fcsh)Build succeeded
    Done(0)
    [Starting debug session with FDB]

    Where is the ”hello world” text?

  • I am getting the following error: C:\Users\Lourdes Martinez\Documents\flex_sdk_3.1.0.2710\frameworks\flex-config.xml(54): Error: unable to open ‘libs/player/10/playerglobal.swc’

    Build halted with errors (fcsh).
    Done(1)
    and evidently, I’m not getting the “Hello world” message. What’s the problem?

  • (fcsh)Build succeeded
    Done(0)
    [Starting debug session with FDB]
    Where is the ”hello world” text?

  • Comments are closed.