Archives for January 2010...

(5 results found)

Update to Clock Class

Tue Jan 26 08:57:45 2010

Get Adobe Flash player

This is just to let you know that I have updated the DigitalClock class that I posted a little while back. The class is now called simply New functions include clockAnalogue() and clockDigital(). Just take a look below to see how to use them.

import Clock;

var clockAnalogue:Clock = new Clock();
var clockDigital:Clock = new Clock();

clockAnalogue.tickAnalogue(hourhand, minuteHand, secondHand, true);
clockDigital.tickDigital(textField, textFormat, true);

In the above code, we first import the Clock class and make two instances of it. One called clockAnalogue and the other clockDigital. These names can be anything you like.

Next we call the tickAnalogue function on the clockAnalogue instance. On the instance clockDigital, we call the tickDigital method. tickAnalogue and tickDigital tell the clock class whether it will be an Analogue or Digital style clock.

tickAnalogue takes four parameters, the first 3 are mandatory MovieClips and the last parameter is optional. The first paremeter represents the hour hand, the second the minute hand, and the third represents the seconds Hand. You can draw these just in code or create them in Flash, and then just pass them in.
The fourth and final parementer is just a Boolean. Setting it to true gives you GMT time. false gives you local time.

The tickDigital method takes 3 paremeters. The last of which is a Boolean and sets GMT or local time in the same way that it does in the tickAnalogue method. The first parameter takes the TextField that will display the time. The second takes a TextFormat to style the time.

..and that's it folks. Again, I hope you find this useful.

Download the Class here

Little Known CSS List Styles

Sun Jan 24 02:38:47 2010

Even though HTML is not a programming language, but rather a markup language, it sometimes amazes me how much HTML has to offer. Just today, for example, I was reading a magazine and discovered some very useful CSS list styles. Most of them I has already seen, but those I hadn't still looked useful. As I live in Japan, the Japanese list styles look particularly useful. Anyway, just take a look below to check them all out. Just click on any of the links to see the style effect in real time.

Useful List Styles

  1. list-style:none;
  2. list-style:circle;
  3. list-style:disc;
  4. list-style:square;
  5. list-style:lower-greek;
  6. list-style:lower-roman;
  7. list-style:uppper-roman;
  8. list-style:lower-latin;
  9. list-style:upper-latin;
  10. list-style:lower-alpha;
  11. list-style:uppper-alpha;
  12. list-style:upper-latin;
  13. list-style:lower-latin;
  14. list-style:decimal;
  15. list-style:decimal-leading-zero;

Useful List Styles in Japan

  1. list-style:cjk-ideographic;
  2. list-style:hiragana;
  3. list-style:katakana;
  4. list-style:hiragana-iroha;
  5. list-style:katakana-iroha;

To use these styles, either put style="list-style:'style';" on the tag you would like to style. Otherwise, import a external stylesheet or use the styles tags at the top of your HTML page and write li{list-style:'style';}

As you can see, there are some really useful ones. It is just such a shame that most coders only get to use some more than others. I would love to see a wider use of these incorporated into the designs of more of the websites that I see on a daily basis. It just seems such a waste not to use them!

ActionScript 3 Digital Clock Class

Thu Jan 21 04:10:47 2010

Something as simple as putting the time on your site shouldn't be a difficult task and so I thought I would share a quick class with you that when instantiated creates and Textfield and tells the current time.

Here's the code.

import DigitalClock;

var clock:DigitalClock = new DigitalClock();
var clockGMT:DigitalClock = new DigitalClock(true);

clock.x = 10;
clockGMT.x = 100;

Here's the result

Get Adobe Flash player

In the example above, we import and make two instances of the class DigitalClock. I have named them 'clock' and 'clockGMT' for obvious reasons.

You will noticed that we pass the Boolean true to the clockGMT instantiation to create a clock that displays Greenwich Mean Time (GMT) which is the local time in the UK. If you don't pass true or false the class will default to the local time (false) of the computer viewing it.

After that, all that's left is to add the clocks to the display list using addChild() passing in the name of each instantiation. I have also set the x position of the clocks so they don't appear on top of one another.

Download the DigitalClock Class here

Getting MySQL Auto Increment

Tue Jan 12 14:52:00 2010

If you have ever written a program that connects to a database using PHP, then there may have been times when you wanted to find the next available Auto Increment value in an MySQL database. The code below will allow you to do just that and it's very simple to use.

$row = mysql_fetch_assoc(mysql_query("SHOW TABLE STATUS LIKE 'votes'"));
echo $increment = $row['Auto_increment'];

Here's how it works. On the first line, we query the database and store the result in the variable $row. You could write this so that you store the query string in a variable and then pass that variable into the mysql_fetch_assoc() function, which is probably more usual. However, I was looking for the minimum amount of code possible for a project that I'm currently working on, so that's the way I wrote it.

On the second line, we store the the value of 'Auto_increment' in the variable $increment and echo it back to see the results. Depending on the database you connect to, you will obviously get different results.

Information about the SHOW TABLE STATUS syntax used and more can be found here at the online SQL 5.1 reference where 'Auto_increment is also listed.

Loading Fonts at Runtime

Tue Jan 5 09:53:51 2010

One of the painstaking things about creating swf files is embedding large font files which often end up bloating your flash movies and causing long wait times for your users. But what if I told you that there is a way to load fonts at runtime? Well, there is and it just so happens that I have prepared an example to guide you through it, allowing you the peace of mind that you can easily import the fonts you need when you need them and create subsets of them when every character in a font set is not necessary, and thus giving you a lot of power indeed.

Creating a SWF Contained Font

First off, you need to create a swf file containing the font that you wish to load into your movies. The big advantage to this is that you can have a library of preprepared swf files containing all your favourite fonts to load when and where you want. To understand how this is done, take a look at the following code.

   import flash.display.Sprite;
   import flash.text.Font;
   public class FontEmbed extends Sprite{
      [Embed(systemFont='OCR A Std', fontName="OCR", 
      mimeType="application/x-font", unicodeRange="U+0041-U+005A")]

      public var ocr:Class;

      public function FontEmbed(){

On lines 7-8, we simply embed whatever font we want to be contained inside the swf file that is to be output on compilation of this class. In this example, I have chosen the font OCR A Std because it is a rather unusual font and will stand out against default fonts when testing to see if the font was actually embedded correctly. To embed your own font, simply change the systemFont string to the name of a font on your system if you don't have OCR A Std, which is highly likely if you are not on a Machintosh. The fontName can be any name you choose to remember this font by. This is important because we will be using this name to load in the font later. In my example, I have chosen the name "OCR" for simplicity. The mimeType is not something to worry about as it simply tells the Flex SDK what type of file to expect. Finally, the real power comes with the use of unicodeRange, which allows you to determine a range of characters you wish to embed. In this case, I have chosen the range U+0041-U+005A which is simply Unicode for A-Z.

There is a great little list of Unicode values to be found here at Wikipedia. Also, if you are running a mac, you could simply open a program such as TextEdit and go to Edit > Special Characters and roll over the characters to display their Unicode values. I'm sure Windows has something similar but don't quote me on that.

Continuing on, any font embedded must be datatyped to a Class, which is what the code on line 10 does. Finally, inside the constructor function on line 13, we register the font using Font.registerFont. Don't forget that to access any method of the Font class, you must import flash.text.Font (see line 4).

Once all that is done, simply compile the class to create the swf file containing your prefered font. As nothing has been added to the display list, nothing will be visible if you choose to view the swf file at this point.

Loading the Contained Font

Loading fonts is pretty simple. Take a look at the following code.

   import flash.display.*;
   import flash.text.TextField;
   import flash.text.TextFormat;
   import flash.text.TextFieldAutoSize;
   public class FontLoading extends MovieClip{
      private var ldr:Loader = new Loader();
      private var txt:TextField = new TextField();

      public function FontLoading()
         ldr.contentLoaderInfo.addEventListener(Event.INIT, loaded)	
         ldr.load(new URLRequest("FontEmbed.swf"));
      private function loaded(event:Event):void{
	 txt.autoSize = TextFieldAutoSize.LEFT;
	 txt.embedFonts = true;
	 txt.defaultTextFormat = new TextFormat("OCR", 22, 0x333333);


On line 11 I have instantiated a Loader called "ldr", which will be used to load the font. The TextField on line 12 will only be used to display the results and is not necessary to load the font itself. On line 16, we add an EventListener to listen for the INIT event which basically means it will be waiting for the load to begin. Once it does, it will call the loaded function on line 20. The loaded function will add the TextField txt to the display list and auto-size it to fit the text on line 22. On line 23, we tell flash to use Embed fonts if it finds any (it should find our font) using txt.embedFonts = true. On line 24, we set the defaultTextFormat font on the TextField "txt" to "OCR". This is the name of the font we set when we compiled the swf containing our font, and this is how the Flex SDK will know which font we would like to use. On the same line, we set the font-size to 22 and the colour to a dark grey (0x333333). Finally on line 25, we give the TextField some text. All that is left is to compile the class and marvel at the wonder of loading fonts at runtime... a truly beautiful thing.

Download Runtime Font Files Here

Most recent posts

  1. Flashcards Maker - the app the helps you learn in a flash
  2. Convert Font Suitcase to TTF in 3 Easy Steps
  3. Rain or Shine - Weather Forecast Available Now!
  4. Getting around Apple's silly rules for iOS 10
  5. Localising App Names for iOS and Android

Search site:

Apps by

Click the app icons to see more info