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
August 12th, 2008
can you Digg it?
is it del.icio.us? 
I’ve just installed the ScribeFire blogging extension for Firefox.
After looking for a decent desktop based blog editor (and considering building one myself on several occasions.) I have to say this one is pretty darn good, HTML support works well and there is also quick Flickr and YouTube buttons on the toolbar so you can insert photos and videos into your posts quickly and easily.
If you’re in the mood to try out a new blogging editor go and grab the extension from the Mozilla Addons site now…
August 6th, 2008
can you Digg it?
is it del.icio.us? 
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;
}
July 30th, 2008
can you Digg it?
is it del.icio.us? 
If you need to do any sort of parameter passing to your AS3 or Flex Swf’s you may be wondering how to do it. In the olden days when you had a _root context on your MovieClips, and thank you very much there were your variables ready and waiting when you loaded your SWF.
Flex / AS3 has a more semantic and structured approach to the problem, well, it puts the values somewhere more semantic and structured at least.
If your application entry point is a subclass of Application you can grab your parameters from MyAppSubclass.application.parameters or in mxml Application.application.parameters.
For example I have a product ID I want to pass to a small swf when I load it.
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="initVars()"
height="65">
<mx:Script><![CDATA[
[Bindable]
public var productId:String;
// Assign values parameters to properties.
private function initVars():void {
productId = Application.application.parameters.productId;
}
]]></mx:Script>
<mx:VBox fontSize="18" fontFamily="Arial">
<mx:HBox>
<mx:Label text="Product Id: "/>
<mx:Label text="{productId}" fontWeight="bold"/>
</mx:HBox>
</mx:VBox>
</mx:Application>
All I have to do is load the swf with a query string tacked on the end of the swf’s url and supply the key, value pair for my variable.
key: productId
value: 2983127 (or any other product id I need, be careful of invalid strings!)
so the swf load url would look something like…
myflex.swf?productId=2983127
The mxml will run straight from Flex Builder 3 so try it out for yourself and try loading the swf you compile into a browser (without HTML) and put ?productId=THX1138 on the end of the url…
Hey presto.
April 22nd, 2008
can you Digg it?
is it del.icio.us? 