This blog has moved to a new location! http://iqandreas.github.com/
Showing posts with label Action Script 3. Show all posts
Showing posts with label Action Script 3. Show all posts

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.
https://github.com/IQAndreas/FDT-Ubuntu-Launcher-Files/zipball/master

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.

Tuesday, February 9, 2010

The Language Reference at the tip of your fingers!

There is no question or dispute about it,
If you want to be a good ActionScript developer, you need to learn how to use the ActionScript 3.0 Language Reference. (Unless you have decided to do all your coding using only primitives...)
I'll write a guide on how to use the language reference some time in the future, but until then, it still needs to be convenient and easy to get to. I will show you how to save the language reference to your hard drive (faster than loading it in from the internet, and then it's also available when you are offline!), and then add it to your bookmarks toolbar.

The end result will look something like this:



I will be using FireFox (version 3.5.7) running on Windows XP. It should be fairly straightforward, and pretty much the same for any browser or operating system, but if you have any difficulties, leave a comment. If you have gotten this to work in a different operating system or browser, please share your results.


Step 1 - Find and download the ActionScript reference from Adobe's website

The newest version of the language reference can be found at:
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/index.html

Note that Adobe often throws around and rearranges their site, so if that should happen, this site will always link you to the most up to date version of the language reference:
http://tinyurl.com/ykacx95


About at the bottom of the page of the online reference, it should say something like "Download a standalone ZIP file version of this reference, including its own local search for offline use, here:" with a link to the ZIP. The current link is as follows:
http://help.adobe.com/support/documentation/en/flash/10/ActionScript3LangRef.zip

Save that ZIP file (about 6MB) to your desktop, and proceed to step 2...



If you are using Flash CS3, the online version of the language reference can be found here:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/

I can't seem to find a downloadable ZIP, however, if you installed CS3 correctly, the language reference should already be stored on your computer in the following directory:
C:\Documents and Settings\All Users\Application Data\Adobe\Flash CS3\en\Configuration\HelpPanel\Help\ActionScriptLangRefV3\index.html


If you are using any other version of ActionScript (such as AS2, Flex, FlashLite etc), the entire list of avialable language references can be found at:
http://www.adobe.com/devnet/actionscript/references/
However, it seems that only the Flex Language Reference and the Flash CS4 Language Reference can be downloaded as ZIP files. Sorry. :(



Step 2 - Extract the ZIP file to an appropriate location

If you can't do this one on your own, you have more to worry about than learning ActionScript.

You can extract the directory to any place that is convenient for you, however, if you decide to move it later you will need to redo the entire procedure, so choose wisely!

Some recommended directories:
c:\Documents and Settings\All users\Documents\AS3 Language Reference\
c:\Documents and Settings\All users\Application Data\Adobe\AS3 Language Reference\
c:\Program Files\Adobe\Flash CS4\AS3 Language Reference\
c:\Program Files\Adobe\AS3 Language Reference\
c:\Program Files\Mozilla Firefox\AS3 Language Reference\
c:\Programming\Flash\Language References\AS3 Language Reference\
c:\AS3 Language Reference\

I will be using the first option for this tutorial as it will be the least likely to be overwritten in case any programs update.


If you are using CS3, play it safe and keep the language reference in the directory where you found it. If you want to have it elsewhere, make a copy.



Step 3 - Add "index.html" and "all index pages"


EDIT: For some reason the context menu option "Open selected links in new tabs" seems to have disappeared, so in order to continue the tutorial you need to install one of the following add-ons:
Linky - https://addons.mozilla.org/en-US/firefox/addon/425
Multi Links - https://addons.mozilla.org/en-US/firefox/addon/13494
Snaplinks - http://snaplinks.mozdev.org/installation.html

For this example, I will be using "Linky", but you are free to use whatever plugin you prefer.


In the directory you downloaded the language reference to, open the "index.html" file into FireFox (or whatever browser you are using).

The site's url should say something like
file:///C:/Documents%20and%20Settings/All%20Users/Documents/AS3%20Language%20Reference/index.html

And you should see a page like this

The main index page for the ActionScript 3.0 Language Reference

To begin, bookmark "index.html" and rename it to "Main Page" or something and place it in a new bookmark folder named "AS3 Language Reference".

For convenience, I added the bookmark folder directly to the "Bookmarks Toolbar", but you can keep them hidden away in the plain old bookmarks menu if you prefer.


Next we will be adding a "search feature" (more like an index with CTRL+F) Remove the "index.html" text from the url bar and hit enter. This should bring up the folder contents in FireFox with the following url:
file:///C:/Documents%20and%20Settings/All%20Users/Documents/AS3%20Language%20Reference/


Select all the links you see from "all-index-A.html" to "all-index-Z.html", right click the selection, and (at least in Linky) choose "Open selected links in tabs". After a while, you should have 27 new tabs opened. You can close down the "folder view" so it doesn't get included when bookmarking.


Go to "Bookmarks > Bookmark all Tabs..." or hit "CTRL+SHIFT+D". Choose where to store these bookmarks, and name the folder for them something like "Search". It may take a few seconds, but once the bookmarks are saved, you can close down those pages. This is easiest by just closing and reopening the window, but if you have TabMix Plus plugin installed, there is a very handy "Close other tabs" option.

Linky - open selected links in tabs

Save all tabs as bookmarks

A quick alphabetical index of classes, properties, and functions is now available in your bookmarks


For the next steps, you will be repeating this procedure quite a bit.

Also, if it makes it easier, you can add the root folder where the language reference is stored as a bookmark as well (I named mine "Browse Folder")



Step 3 - Add the packages


Next we will be adding the following packages as sub folders of the bookmarks menu:
adobe.* (only a few files)
air.* (if you don't develop in AIR at all, you can ignore this one)
fl.* (Flash components)
flash.* (All the actual class files - this one is the most important!)

This part is the one that takes the longest. Unless you have a trusty army of Oompah Loompahs to do the job for you, prepare to take out at least half an hour in bookmarking them all. If you have a short attention span, bookmark them small parts at a time over time.

In any order you like, start by opening one of the subfolders with the matching package name, and in most folders, you will need to open an additional sub-folder package.

I'm going to start with "flash.accessibility" (in folder "flash\accessibility\") and start working down the list in alphabetical order until the entire flash directory is added.

Use Linky to open the list of classes into your tabs


Keep doing this to all 4 folders (and their respective subfolders) until you get an organization something like this in your bookmarks toolbar:

Browsing for the documentation for flash.display.MovieClip


Wohoo!! Almost done... (After all that you probably don't want to see another bookmark again, but bear with me. It is definitely worth it and VERY convenient once it's done!)



Step 4 - The global package and Appendix



There are several classes just laying their in the main folder that don't have a package. You could add them directly to your bookmarks toolbar, or you can group them into a new "global" folder to avoid clutter.

Better organized global classes and functions bookmarks

I found, the easiest way to track down all global classes, instead of guessing which ones are classes and which ones are just HTML pages, open the page named "class-list.html". It will contain a list of all the global functions and classes.

Note that even though the classes are organized into separate HTML files, the global functions are all stored in one single HTML file (named "package.html"). So, instead of selecting all links on the page, only select the classes, and bookmark them. After that, go back and bookmark "package.html". If you have any use for it, you can also bookmark "package-classes.html", which is basically a list of all classes and functions in the top level package.

You can even add the pages "operators.html", "statements.html", and "specialTypes.html".


Finally, the Appendix ("appendix.html") contains pages such as a list of errors and what they mean, some AS2 to AS3 migration help, and other information. You can either add this single page and bookmark it, or select all outgoing links and bookmark those instead, creating a subfolder named "Appendixes".


The only page left is "conventions.html", and unless you will be checking on it every few days, I wouldn't bother adding it as most of the Language Reference conventions are quite self-explanatory anyway.



Last thoughts



So, that's it. If you did everything right you should have a bookmarks menu which is easy to navigate around in, and has really helped me at times.



An added bonus is that if you start typing in something in the address bar, FireFox will automatically recommend pages in your bookmarks.
Firefox will auto-complete any text you type in with a class in the language reference from the bookmarks if a match is found


I'll create a post in the near future which better uses the "search" ability of the language reference, but that is yet to come.