---
id: 410
title: com.hello.formatters.GuidFormatter
slug: comhelloformattersguidformatter
date: '2008-09-07T23:29:01Z'
modified: '2008-09-07T23:29:01Z'
status: publish
type: post
author: pmoelgaard
categories:
  - ActionScript 3.0
tags: []
excerpt: null
canonicalPath: /posts/comhelloformattersguidformatter
featuredImage: null
commentCount: 0
wordCount: 160
readingTimeMinutes: 1
hasMedia: false
hasVideos: false
url: 'https://forwardthinking.pemo.me/posts/comhelloformattersguidformatter'
---
Today I needed a fomatter for GUID's.

I made a quick and dirty extension to the Formatter base class that uses our existing com.hello.core.Guid class to fetch a format constant and then use an instance of the [mx.formatters.SwitchSymbolFormatter](http://livedocs.adobe.com/flex/3/langref/mx/formatters/SwitchSymbolFormatter.html) to apply the pattern to the string representation of the Guid we want to format.

The implementation looks like this... don't think too much about the details of the implementation – it has been simplified to serve as example of the general idea.

**package** com.hello.formatters { **import** com.hello.core.Guid; **import** mx.formatters.Formatter; **import** mx.formatters.SwitchSymbolFormatter; **public** **class** GuidFormatter **extends** Formatter { **public** **function** GuidFormatter() { **super**(); } **override** **public** **function** format( value:Object ) : String { **var** result:String = **""**; **var** valueStringLength:Number = value.toString().length; **switch**( valueStringLength ) { **case** 36: result = value.toString(); **break**; **case** 32: **var** dataFormatter:SwitchSymbolFormatter = **new** SwitchSymbolFormatter(); result = dataFormatter.formatValue( Guid.FORMAT, value ); **break**; **default**: error = ERROR\_MESSAGE; **break**; } **return** result; } **public** **static** **const** ERROR\_MESSAGE:String = **"guidFormatterErrror"**; } }
