Johnvh.com - home of Dallas, Texas based Flash Developer and web enthusiast John Van Horn

Online home of John Van Horn

Ignoring files in Flex Builder Navigator

I don't like seeing .svn or CVS files in my Flex Builder/Eclipse workspace. I'll never need to edit those files directly, and if I do, I won't use Flex Builder to do it. But if they're in your project, they'll show up in the Navigator panel. Everywhere.

Every directory in your project will have a .svn folder.

Every directory in your project will have a .svn folder.

Fortunately, Eclipse provides a way to filter files in the Navigator, but a) it's rather hidden, and b) it's not obvious how to add filters. In the Navigator panel, hit the down arrow in the top right corner and select "Filters...".

Navigator panel options.

Navigator panel options.

Here's the list of filters you get by default:

Default Filters

Default Filters

What? No "add filter" option? No "edit"? I guess you could use the ".*" filter, but that would hide every file or directory whose name starts with ".". That may or may not be acceptable, depending on the type of project or files your working with. What if you had a .htaccess file in your project?

Fortunately again, there is a mechanism for adding additional filters, but it's not obvious. It involves editing the plugins.xml file for the Flex Builder editor plugin. You can find this plugin in the eclipse plugins folder (located in same place as Flex Builder.app) in your Flex Builder install. It's called com.adobe.flexbuilder.standalone_3.0.194161, and it's located for me at:

CODE:
  1. /Applications/Adobe Flex Builder 3/plugins/com.adobe.flexbuilder.standalone_3.0.194161

So navigate there, and edit plugins.xml. You're looking for the extension node whose attribute point is "org.eclipse.ui.ide.resourceFilters". Under that node is where the default filters are defined. All you have to do is add another one and save the file:

Flex Builder editor plugin.xml, with svn filter added.

Flex Builder editor plugin.xml, with svn filter added.

The remaining step is to restart Flex Builder, using the -clean option. Since the plugin.xml file is either cached or compiled in somewhere, using the -clean option tells the Eclipse executable to reload all plugins and configs. This requires use of the Terminal:

CODE:
  1. $ cd /Applications/Adobe\ Flex\ Builder\ 3/Flex\ Builder.app/Contents/MacOS
  2. $ ./FlexBuilder -clean

When Flex Builder launches, you should now see the filter you just added in the filters window. Thanks to Robert Ames for telling me how to launch Flex Builder with arguments.

New filter added.

New filter added.

Master bathroom progress

I got a lot done this weekend: the shower was grouted, and I got the vanity, medicine cabinet, and lighting installed! Next up, counter top.

Grouted! All the shower needs is some finished plumbing and little bit of caulk.

Grouted! All the shower needs is some finished plumbing and little bit of caulk.

Vanity, medicine cabinet and lighting.

Vanity, medicine cabinet and lighting.

More pics on Flickr.

Master bathroom progress

Finally finished tiling the shower last weekend. I don't know why it took so long, but it did. I should be able to grout and call the shower area officially done hopefully this weekened.

The shower, finally tiled.

The shower, finally tiled.

Are your event handlers bad?

Event handlers can be bad. They're not intrinsically bad - that's how shit gets done in AS3. It's the way they often get written that can be bad. Consider the following example:

Actionscript:
  1. package
  2. {
  3.     import fl.motion.Color;
  4.    
  5.     import flash.display.DisplayObject;
  6.     import flash.display.Sprite;
  7.     import flash.events.Event;
  8.     import flash.events.MouseEvent;
  9.  
  10.     public class Nothing extends Sprite
  11.     {
  12.         private var square:Sprite;
  13.        
  14.         public function Nothing()
  15.         {
  16.             square = new Sprite();
  17.             square.graphics.beginFill( 0xFFFFFF, 1 );
  18.             square.graphics.drawRect( 0, 0 , 50, 50 );
  19.             square.graphics.endFill();
  20.             square.addEventListener( MouseEvent.CLICK, click );
  21.             addChild( square );
  22.         }
  23.        
  24.         private function click( event:MouseEvent ):void
  25.         {
  26.             var clickedObject:DisplayObject = event.target as DisplayObject;
  27.             var tint:uint = 0xFF0000;
  28.             var color:Color = new Color();
  29.            
  30.             color.setTint( tint, 1 );
  31.             clickedObject.transform.colorTransform = color;
  32.         }
  33.    
  34.     }
  35. }

Great. So a sprite is tinted red when its clicked. But what happens when you have to tint that sprite at other times, like when the application loads? All the code that does the tinting is locked up inside the event handler - the problem there is that the event handler needs a MouseEvent to run.

A better, more reusable, and more modular approach would be:

Actionscript:
  1. public function tint( obj:DisplayObject ):void
  2. {
  3.     var tint:uint = 0xFF0000; //or better, make this an argument
  4.     var color:Color = new Color();
  5.            
  6.     color.setTint( tint, 1 );
  7.     obj.transform.colorTransform = color;
  8. }
  9.  
  10. private function click( event:MouseEvent ):void
  11. {
  12.     var clickedObject:DisplayObject = event.target as DisplayObject;
  13.     tint( clickedObject );
  14. }

You see? The event handler just notifies us that something needs to be tinted. The actual tinting happens elsewhere. Now, code that does work does not need anything other than a reference to a DisplayObject to run! Now, you can tint an object when the application loads. You can tint an object on a timer. Now, you can tint anything, at anytime! Now its testable and reusable! And, it's a very easy concept to master.

Get what you need from an event object, and get out.

When you write event handlers, think about what they are actually doing. What do you actually need from the event object? How would you test the event handler? Or better yet, how would you make the same thing that happens in the event handler, happen without the event?

Twitter
Del.icio.us links
» My delicious bookmarks