Tagged with Tutorial

FlexBuilder / Eclipse keyboard shortcuts that will change your life

by

  • Control + O = Open an outline of functions within the current class to jump to.
  • Command + Shift + T = Jump to a type (class or interface). Only works when an .as or .mxml file is open.
  • Command + Shift + R = Jump to a resource. Includes classes and any other files (such as XML files)
  • Command + L = Jump to a line number
  • Command + Shift + C = Wrap / Unwrap selected text in a block comment (/* */)
  • Command + Shift + / = Comment / uncomment the selected line using  an inline comment (//)
  • Command + Shift + D = Add ASDoc style comment
  • Command + D = Delete the selected text
  • Command + UP = Move the selected up
  • Command + DOWN = Move the selected text down
  • Command + Option + UP or DOWN = Duplicate the selected text above or below the selected line
  • Command + X = Make selected text ALL CAPS
  • Command + Y = Make selected text all lowercase
  • Command + Shift + R = Rename selected element (using refactor)
  • Command + M = Maximize / Minimize current view
  • Control + Tab = Jump to an open file editor
  • Command + Shift + L = Keyboard command list. Press it again to edit commands.
  • Command + F = Find / Replace dialog.
  • Command + Shift + G = Find any references to the selected element within your project
  • Command + Click or F3 = Jump to the definition of the selected element
  • Command + J = Find within document. Type the word you want to find then use up and down to skip between instances. Press ESC to cancel.
  • Command + Shift + P = Jump to matching bracket. e.g. jump from } to {
  • Control + H = Search (rather than find) allows you to search within the entire workspace.
  • Tab / Shift + Tab = Indent / Un-indent selected text.
  • Command + Option + Left / Right = Jumps to the location of the previous / next edit without undoing your change.
Tagged , , , , , , , , ,

Q&A – is, as, and type conversion

by

A question from a reader gave me an excuse to write a huge rant about type conversions:

I’m doing a little exercise in a book that makes a textfield in which each letter can only be entered once. Not very useful, more of a teaching thing really. However there’s a bit of code that says:

var tf:TextField = event.target as TextField;

I don’t understand this at all! What the hell is event.target as TextField? Anyway here’s the full code for context’s sake:

package com.FoundationAS3.ch6 {

	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.events.TextEvent;

	public class PreventDefaultTest extends Sprite {

		public function PreventDefaultTest() {
			var tf:TextField = new TextField();
			addChild(tf);

			tf.width = stage.stageWidth;
			tf.height = stage.stageHeight;
			tf.type = TextFieldType.INPUT;
			tf.wordWrap = true;

			tf.addEventListener(TextEvent.TEXT_INPUT, onTextFieldTextInput);
		}

		private function onTextFieldTextInput(event:TextEvent):void {
			var tf:TextField = event.target as TextField;
			if (tf.text.indexOf(event.text) > -1) {
				event.preventDefault();
			}
		}
	}
}

Thanks,
-Neal

My response after the jump.
Continue reading

Tagged , , , , , , , ,

Tip: Adding version checking to your external code library

by

Since version 1.0 of a code library that I’m sure you’re tired of me talking about came out, I have been making steady updates, some of which break legacy code. I was also having trouble keeping track of which version of the library a particular demo was written for. In order to make sure that the new code library doesn’t cause unpredictable results for the old implementations I added a version check to the main class.

This version check is very simple. It checks a version number in the client code against a version number of the library (or external classes) when the main class of the library is initialized. It is also completely optional (so average users don’t need to mark up their code with version numbers).

Here’s an example:

Say you normally initialize your library using:

MyLibrary.initialize();

Which calls the initialize method:

public static function initialize():void {
   // initialize library here
}

If the external code changes unexpectedly (say through an SVN update) this could cause problems that are difficult to trace. The solution is to modify the initializer to match the client code version with the initializer version.

public static const VERSION:String = "1.6";
public static function initialize(versionCheck:String = VERSION):void {
   if (versionCheck != VERSION) {
       throw new Error ("The version check failed! This library is version " + VERSION + ". Update your code or GTFO!");
   }
   // initialize library here
}

And when you run the initializer, use the version number you’re expecting.

MyLibrary.initialize("1.6");

Some things to notice with this approach:

  • I used a string instead of a number for the version number so that it would allow for sub-sub version numbers and other markers, e.g. “1.6.24 beta r545″
  • Because there is a default value for versionCheck in the initializer, providing a version number is optional. Using MyLibrary.initialize() will still work and throw no errors.
  • Unfortunately, there is not much you can do if the version numbers don’t match except to warn the client that the external code has changed. Still, I’ve found this to be very useful.

The code for my initializer in its entirety after the jump…
Continue reading

Tagged , , ,