As we know, flex Builder 2 (FB) is an Eclipse based IDE that will make creating/editing/debugging flex code very easy for flex developers. For those developers who come from java background, Eclipse may already be the favorite IDE for coding. For those who are not familiar with Eclipse, it may take some time to get use to it. Here are some tips and tricks for using Eclipse.
1. Keyboard shortcuts: You can get a complete shortcuts list within Flex Builder by pressing CTRL-SHIFT-L, or from menu Help –>key Assist…; or look at the list online here.
Here are my favorite shortcuts:
1). ALT + / ( Word completion) —- You can type the first couple of letters of any variables\function\class name, FB will complete the word for you, reduce typing and typos.
2). Ctrl + Space (content assist) —- When your tag is too long for one line, and you put the code on separate line, the content assist doesn’t seams to come up any more. If you use Ctrl + Space, the content assist will popup again.
3). Ctrl + mouse click on a variable/function/class name —- you may have variable/function/class in the code that is defined in some place else. To look at it, you can hold down the ctrl key, and then use the mouse to point to the name of the variable/function/class name you are interested and click it, this will take you to where it is defined.
2. Running a non-default mxml file in the project from Flex Builder
When a project is created, FB will create a default mxml file as the main application file for you. You can create multiple application files in one project from FB, and FB will add them to the application list for you. However, if you copy an application file (mxml files with mx:Application tags) into the project, and try to run that file from FB, you may find that FB will not execute it. This is because FB only runs the mxml file that has been added into the application list of that project. Since the file you copied is not in the application list, FB does not know about it.
To add application files into the application list, simply to the following:
1). open the Navigator view in FB, and select all the mxml you are going to execute.
2). Right click on the files you just selected, go to “application management” –> “add to application list”.
Now you have added the mxml to the application list, you can run any of those mxml in FB.
3. Error displayed when there is no error in the currently opened code.
Sometimes you may see errors been displayed in the problems view, but you are almost sure that there is no error in the mxml page you are editing. Then where is the error coming from? Well, the problems view display the error not only from the file you currently opened, but also the errors from any file in any opened project. For better management, I would do the following:
1). Close all the projects that you are not using, only open the project you are currently working on. By doing so, you are also reducing the time to starting your FB, as well as reducing memory consuming while running FB.
To close or open a project, right click on the project name from the Navigator view, and click on “close project” or “open project”.
2). When errors displayed in problems view, pay attention to the “Resource” and “In folder” columns, which will tell you the file name and location of the code that contains the errors. If that file with the errors has nothing to do with the file you are currently working on, then you can ignore the errors for the moment, and continue to run the file. Your code should run successfully.
4. Clean up errors in problems view
When errors displayed in problems view, you can double click on an error, and it will take you to the line where the error occurs in the code. After you edited the code, you will have to save the page to make the change effective:
If you turned on “build automatically” (this is on by default), then the error will disappear once you saved the file after edit the error.
If you did not turn on the “build automatically”, the error will not disappear until you execute the page. So you should set “build automatically” on for development.
To do so, go to menu Project — > check “build automatically”
5. clean up project
When you find there are problems in your project, like certain mxml page is not updating the modification, or some asset files are missing, you can correct it by doing “clean” on the project (Project–>clean). Other times a simple “clean” will not do the trick.
For example, you may see FB get closed when you try to open certain mxml in the project. This is mostly caused by the project has been messed up. Other times the project may not work properly because of some user error like deleted html in the bin directory that is needed to run the page. In these cases, it is much easier to clean up the project by recreating it. To do so, follow the steps below:
Right click on the project name you want to recreate from Navigator view, and then select “delete”. On the popup dialog, make sure you checked “do not delete contents”. After the project has been deleted, you can recreate it again. Now the project should be cleaned up, and things should be working properly again.
6. Flex Builder running slow or hang, or get “out of Memory” message
Flex Builder will consuming memory over times, especially when you have a lot of projects created in FB. You can monitor the memory usage of FB from windows task manager. Look at the javaw.exe process, the above mentioned problems usually happens when the memory usage of javaw.exe is too height. You can close and restart the FB to clean up the memory.
By default, FB set the heap size for Java virtual machine in FlexBuilder.ini as following:
If you exceed the maximum value, “OutOfMemory” errors can occur.
If your system has more total memory available, then you can increase the maximum heap size value. The rule of thumb used to be set the maximum heap size no more than half of the total memory available. However, with the new features and settings in the newer version of JDK, there are more factors you need to consider when deciding what is the best maximum heap size you can use. You can consult articles about heap size online.
To change the heap size settings, you can modify them in FlexBuilder.ini under the FB root directory.
If you start FB by command line (or using Eclipse), then you can change them by command line (or FB2 shortcut) such as “C:\Program Files\Adobe\Flex Builder 2 Beta 1\FlexBuilder.exe” -vmargs -Xms256M -Xmx512M
7. NullPointer Exception when open FB
If you leave some files open when you close FB and restart FB later, by default FB will open the files you previously opened. If one of those opened file has been deleted already at this time, then FB will throw NullPointer exception. All you need to do to get rid of the exception is to close that file.
8. Modified asset file does not get updated
Once you have compiled your application page and want to modify some of the asset files that are not embedded, such as modify one of your xml files or adding more image files, you may find that they are not updated after recompilation.
To ensure the assets get updated in FB, make sure you turned on “copy assets” (This is set by default):
Project —> properties—>flex compiler, then make sure you checked “Copy assets not embedded in the built SWF to the output directory”
If for some reason the modified files did not get copied into the output directory (by default it is the bin directory), then you need to copy the modified file into the output directory manually. That will make the update show up when you re-run the application.