AS3 Singleton - FDT Template

Ok, here we go again, AS3 and Singletons have been discussed almost as much as Peak Oil, but never-the-less, allow me to present yet another Singleton implementation, wrapped up in a neat little FDT template.

package ${enclosing_package} {
	
	/**
	 * @author ${user}
	 */
	public class ${enclosing_type} {
		
		private static var _instance : ${enclosing_type};
		private static function hidden() : void {}

		public static function getInstance() : ${enclosing_type} {
			if( _instance == null ) {
				_instance =
					new ${enclosing_type}(hidden);
			}
			return _instance;
		}

		public function ${enclosing_type} (h:Function) {
			if (h !== hidden) {
				throw new Error( "${enclosing_type} and can only be accessed through ${enclosing_type}.getInstance()" );
			}
		}
		
		${cursor}		
	}
}


Download the FDT template XML

Add comment August 12th, 2008

FDT Template for Getter / Setter methods.

If you’re being a good Flex / AS3 dev, you are probably wrapping your class member properties with public getter and setter methods.

If you’re not, you really, really should…

Getters and Setters, otherwise known as accessor methods, or mutator methods (among other things), are very helpful. They allow you to make your public properties have a far greater set of controls and features. I won’t go into all the details here, I’m assuming that you, like me, only fail to set them up because typing…

public var classMember : String;

Is slightly quicker than typing…

private var _classMember : String;

public function set classMember( value : String ) : void {
        _classMember = value;
}

public function get classMember( ) : String {
        return _classMember;
}

Anyway, if you are an FDT user, (or your chosen IDE has a templating feature) you can create a template to do this for you.

Read/Write member … (template name member)

private var _${name} : ${type};

public function set ${name}( value : ${type} ) : void {
        _${name} = value;
}

public function get ${name}( ) : ${type} {
        return _${name};
}

And then it will only take as long as setting up a public var, but with all the goodness that comes with using getter/setters…

You could setup templates for a read only member, and a write only member too…

Read only member … (template name rmember)

private var _${name} : ${type};

public function get ${name}( ) : ${type} {
        return _${name};
}

Write only member … (template name wmember)

private var _${name} : ${type};

public function set ${name}( value : ${type} ) : void {
        _${name} = value;
}
Download the FDT template file.

Add comment July 30th, 2008

FDT 3 Out of memory error

When you first get started with FDT3 from PowerFlasher http://fdt.powerflasher.com / http://fdt.powerflasher.de you will probably get the message…

Not enough memory to run FDT - add the following line to your eclipse.ini

-Xmx512m

On a windows machine the eclipse.ini is easy to find, and should be in the same folder as eclipse.exe, editing the file in notepad and altering the line

-Xmx256m

to the value above, should be straightforward. If you struggle with opening and saving files in notepad, sadly this blog post isn’t going to give you the file editing 101 that you sorely need.

If you are cool with the file change, restarting Eclipse and opening the FDT perspective will solve the issue.

On a Mac OS X machine things are a tiny bit trickier, the eclipse.ini file is tucked away inside the Eclipse application package, which you probably have stored in your Applications folder.

The quickest way to get at the eclipse.ini file is to Ctrl + Click the Eclipse application and select the *Show Package Contents* option from the menu.

If you then navigate to Contents/MacOS/ inside the package you’ll see eclipse.ini edit it with TextEdit or whatever you like to use to edit text files (TextMate http://macromates.com/, Eclipse, BBEdit?) and change the line

-Xmx256m

to read

-Xmx512m

Save eclipse.ini and close the finder window, restart Eclipse and you should be good to go.

This information is probably in the FDT forum, but I just figured this out five minutes ago and decided to post here instead.

Add comment March 3rd, 2008

FDT 1.5 Released

Powerflasher FDT 1.5.1 for Eclipse 3.2 is now available...

From the Powerflasher site:

Thanks to everybody for the patience. The new Powerflasher FDT 1.5 version is available from now on. It is a free minor update for all FDT fans. We hope the development time for version 2.0 with AS3 support feels short with it.

New Features:

  • Eclipse 3.2 support
  • MAC help update improved
  • Better UTF-8 Support
  • New: Project- and workspace wide reference search
  • New: Mark occurrence in the editor area
  • New: External SWF Viewer (ESV) with ANT support (windows only for the first step)
  • New: classpath editor (imports projectclasspaths to the Flash IDE)

Also new for everyone who was not involved in the public beta:

  • New: fdt.flashCompile ANT new option failonerror="true/false"
  • New: FSCommand2 added to TopLevel.as
  • New: Help Panel rework, also works on mac now
  • New: Quickfixes for foreign types
  • New: Function Variable QF to create a method
  • New: Console LineTracker for MTASC Problems(enables ProblemHover)
  • New: Quick-View: Type Dependency (Ctrl-U)
  • New: Texthovers and Declarations in Comments and Strings
  • New: Editor "Mark Occurences"
  • New: "Set Returntype" Quickfix with type-detection
  • New: Search References
  • New: Show variable-initializer in JavaDoc e.g. var a : String = "Hallo";
  • New: TextEdit - Folding actions
  • New: Other Perspectives from Flash Perspective available
  • New: File associaton of AS-Files via Content Types ("ActionScript Source File")
  • New: Ant-View available from Flash Perspective
  • New: Parser Performance optimizations
  • New: Folding of multiple singleline comments
  • New: Autoclosing of blockcomments optional
  • New: ANT Task "fdt.browse" opens external browser
  • New: Editor Links to AS-Language Elements
  • New: TODO Marker "//!"
  • And of course bugfixes and small other improved things

IMPORTANT: FDT from now on needs Eclipse >= 3.1 and so is not running on 3.0.x any more!

The update is quite easy:

Launch Eclipse, Help -> Software Updates -> Find and Install and select "Search for new features to install". Then mark the checkbox with the Powerflasher FDT site and its done.

We´ve made every update in the last months on the test URL for public beta test. If you participated on it, you already know some of the new features but especially the classpatheditor and the external SWF viewer will be new for all of you. So we hope that we were able to clean out all major bugs in this period but to be realistic, there might be still some. (Why does the bloggers need to be so fast)

Please, post things you find in the bugforum http://www.powerflasher.com/fdt/forum/viewforum.php?f=12 The team will try to fix it quickly.

We hope you will really enjoy it and love the new release as we do. It is still more pure coding comfort.

The Powerflasher Team

1 comment October 31st, 2006