This blog has moved to a new location!

Tuesday, January 17, 2012

Ubuntu: Adding FDT to the list of Applications

This post can be found on the new blog at Ubuntu: Adding FDT to the List of Applications
In this guide, we will add FDT to the list of installed applications, and optionally, install a script which "resets" the internal SWFViewer in case it won't open after closing improperly.

The following guide was written for 32bit FDT5, but may still work for future or previous versions of FDT. These instructions can of course also be used for any application that doesn't come with an Ubuntu installer, adjusting the  files appropriately.

If you are running Ubuntu, I'm assuming you already know how to use the basics of the command line and how to manipulate (create, delete, change permissions) of files. If anyone wants more details, post a comment and I'll clarify.

I'm assuming you have already downloaded FDT (they have a free version if you aren't already using FDT) and extracted the archive.

I would recommend saving the files to /opt/fdt5 (may require admin access, which is easily done without messing with the command line by running  gksu nautilus , assuming you are still using the default file browser) Depending on what extraction tool you use, you may also need to change the permission settings for the files to allow access for all users.

Download the FDT5 Launcher files

If you want to do this the easy way, download the pre-made files from the GitHub repository and install them to the locations specified in the README.

You are all done. Enjoy!

Alternatively, you can do all the dirty work yourself (if so, keep reading).

Creating the FDT5 Launcher Files manually

Create a new file named FDT5.desktop with the following contents:

If you want the file to be available to all users of the computer, save the file in /usr/share/applications/
Alternatively, if you only want the currently logged in user to have FDT show up in the application menu, save the file to ~/.local/share/applications/

Next, create the following script, and save it as /usr/bin/fdt5

Note that the script may be a tad more complicated than it needs to be, but this is the script I'm using since I had to jump through a few hoops getting FDT to work properly in Ubuntu.

You also need to set the icon for the application. The default Eclipse icon is okay, but on my system, both Eclipse for Java and FB4Linux use that same icon, so I would prefer being able to tell them apart.

I included FDT's fancy, blue dodecahedron icon in the repository, used with permission from Powerflasher GmbH. You can use the icon provided in the repository, or use your own, but which ever icon you use for FDT, make sure to save it to /opt/fdt5/fdt-icon.png

Finally, if you want FDT to stay in the launcher bar, start up FDT, right-click the icon in the launcher, and make sure "Keep in Launcher" is checked.

Cleaning the SWFViewer settings

If the built in FDT SWFViewer quits improperly (which happens from time to time when running into AS3 errors) it will not open the next time you run the SWF. The solution is to delete a few config files for the plugin, which is a simple task, but gets annoying when you need to constantly delete the files.

The following script will delete said config files (assuming FDT is installed to /opt/fdt5 as recommended) though I wish FDT had a button for this inside the IDE instead.

Save the script to /usr/bin/fdt5-clean and run it by typing fdt5-clean into the command prompt. The script does not require admin rights to run as long as your FDT install folder has full permission for all users.

Leave any further questions or problems in the comments and I'll try to help sort them out.

What Beginners need to know about Performance and Garbage Collection

Another category of beginner questions that often appear on the Kirupa forums are about performance and garbage collection. Some common concerns:
  • How do I make sure my MovieClips are garbage collected? Is setting everything to null enough?
  • Should I always remove all my event listeners?
  • Someone told me it's better to use int instead of uint because it's more efficient.
  • I used "while(--i)" instead, because it is much more efficient than for loops.
  • hitTest() is really slow! Every site tells me I should never use it.
My answer to all those questions: Don't worry about it.

Don't get me wrong, if you are the type of person who worries about these sorts of things right now, you will make a terrific developer one day! But worrying about these things now is just going to make your code more complicated and much more difficult to manage.

Strive to make your code clear and readable

As a beginner, this should be your first and foremost rule. If you scratch your head every time you read your own code, coding will be overwhelming and debugging will be hell.

Take these two identical chunks of code as an example:

The first chunk of code is much more efficient than the second, but I wouldn't want to be the developer that find bugs in that project.

So should I never worry about performance?

Not at this point, no. First make sure you have learned the basics and syntax of ActionScript.
Then, make sure you really know the basics of ActionScript (instead of just thinking that you do while perched on top of mount stupid. Believe me, we have all been there). Finally you can start learning about standard coding conventions and basic performance improvements.

Keep in mind, most performance optimization tips (such as using int instead of uint) will shave milliseconds off your total time if you do tens of thousands of calculations each frame.

Often times, the extra milliseconds won't make a hill of beans difference, so worrying about them while writing the code is a waste of resources. Test your code, and make sure your project works. Then, if (and only if!) there is a problem with performance after everything is complete and working, you can go back and find which areas need optimizing.

Why Garbage Collection doesn't matter

Same principle as with optimization, don't worry too much about garbage collection unless you are building an enterprise-level application. Flash is actually pretty good at taking care of things for you and making sure everything gets disposed of properly. Even if it misses an image here or there, what is one measly Bitmap for a computer with +2GB of RAM? Users won't notice the difference if your game uses 17 MB instead of 16 MB.

And remember, it's all disposed once you close the SWF anyway.