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
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
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.
March 3rd, 2008
Thanks go out to Adobe this week, for opening up the AMF (Flash remoting message format) specifications.
A PDF is available from here…
December 22nd, 2007
All the kids are debugging with Flash Debug Player these days, (haven't you heard?)
For those of you that don't know, the Debug version of the player sends trace commands to a text file which you can watch with a variety of tools, but we'll get into that later.
To get the Debug Player visit http://www.adobe.com/support/flashplayer/downloads.html and get the latest Netscape (Firefox) and ActiveX debug players.
With the latest upgrade of Flash Debug Player (9,0,28,0) there's been a few changes to accomodate the wonderful(?) Microsoft Vista, Which imposes certain security restrictions. Please note: this post only relates to Windows.
Adobe have provided documentation for the debug player, and for most people it'll work just fine, however, if you're in a corporate environment no doubt you have a roaming profile and this is where the fun begins.
Previously the environment variables %HOMEDRIVE% and %HOMEPATH% were used by the debug player to find it's settings file mm.cfg. It appears that this is no longer the case (the Adobe livedocs page doesn't tell you this.)
It seems that %USERPROFILE% is now used to determine the location of mm.cfg which will allow you to set the config of Flash Debug Player.
The rest of the information in this LiveDocs page is fine. I'll save you the trip over and give you the rest of the infor. The new fixed location of the Player log file is: %USERPROFILE%\Application Data\Macromedia\Flash Player\Logs\flashlog.txt and within the mm.cfg the settings now available are...
|
Property
|
Description
|
ErrorReportingEnable
|
Enables the logging of error messages.
Set the ErrorReportingEnable property to 1 to enable the debugger version of Flash Player to write error messages to the log file. To disable logging of error messages, set the ErrorReportingEnable property to 0.
The default value is 0.
|
MaxWarnings
|
Sets the number of warnings to log before stopping.
The default value of the MaxWarnings property is 100. After 100 messages, the debugger version of Flash Player writes a message to the file stating that further error messages will be suppressed.
Set the MaxWarnings property to override the default message limit. For example, you can set it to 500 to capture 500 error messages.
Set the MaxWarnings property to 0 to remove the limit so that all error messages are recorded.
|
TraceOutputFileEnable
|
Enables trace logging.
Set TraceOutputFileEnable to 1 to enable the debugger version of Flash Player to write trace messages to the log file. Disable trace logging by setting the TraceOutputFileEnable property to 0.
The default value is 0.
|
As far as setting up your mm.cfg file goes, it's a simple text file.
Using notepad enter the following lines
ErrorReportingEnable=0
TraceOutputFileEnable=1
Then save as the file to %USERPROFILE%/mm.cfg
If everything is working ok you will be able to read trace messages from Flash in the file %USERPROFILE%\Application Data\Macromedia\Flash Player\Logs\flashlog.txt
Log viewers...
There are a number of tools out there to view log files, and there are some which specifically target the Flash Debug Player, however due to the latest changes, many of these no longer work properly...
FlashTracer by Alessandro Crugnola (of SEPY fame) is a FireFox extension which will follow flashlog.txt output. You can get it here
A nice alternative is Log Viewer from BrineSoft a bog standard windows based file watcher.
Of course for the truly hardcore there's the unix tail command, available to windows users via the Cygwin project. If you want to play with that one, it's for command line veterans only.
Hopefully now you can stop mucking about with these XMLSocket or LocalConnection solutions, (or heaven forbid TextField.. I ask you!)
February 1st, 2007
Previous Posts