Wednesday, December 23, 2009

Overriding the Java toString method using For loop

This solution uses a combination of reflection, constants and regular expressions to build a meaningful toString output:

private String TO_STRING_FIELDS = "email isPKI isTrustedRoot isITU_TX509 caName"

@Override public String toString() {
try {
StringBuilder result = new StringBuilder();
//String newLine = System.getProperty("line.separator");
String[] fieldList = TO_STRING_FIELDS.split( "[\\s,]+");
Field curField = null;
for (String f : fieldList) {
curField = this.getClass().getDeclaredField(f);
result.append(" " + f);
result.append(": ");
//requires access to private field:
result.append( curField.get(this) );
} catch (Exception e) {
System.out.println("Error in toString for class: " + this.getClass().getName() + "\n" + e.getMessage());

return null;

Refurbishing a Morgan 30

Hull Preparation and Painting

After all the work I did restoring my Flying Scot this summer, I can imagine what a labor (of love) this Morgan 30 refurb was. There are a lot of great tips and experience to be gleaned from his notes.

Tuesday, December 22, 2009

Flex Relative paths for embedded images in buttons with @Embed

Flash, Flex and ActionScript: Relative paths for embedded images

Setting the @Embed source with an absolute path (based on flex_src root) :
<mx:Button icon="@Embed(source='/assets/blue_delete.png')" />

Wednesday, December 2, 2009

as3corelib Contains Crypto Utils for FLEX MD5 Hash

I needed to store MD5 hashed passwords in the database and was delighted to find the as3corelib already contains the necessary libraries.  While there are many more features, I only needed the MD5 Hash function so I only copied in the com.adobe.crypto.MD5 and com.adobe.utils.* files.  With the .as files added to my Flex project, hashing the password was a simple as calling:

    MD5.hash( passwordComp.getPassword() );


I verified that it returns the same hash as the MySQL MD5 function

UPDATE user_table SET password = MD5(‘change_me’) WHERE username = ‘sandman’