In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

flash on 2011-2-14

Get Adobe Flash player
by mischa.lang 14 Feb 2011
    Embed
/**
 * Copyright mischa.lang ( http://wonderfl.net/user/mischa.lang )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/wjMj
 */

package {
  import flash.display.Sprite;

  import flash.utils.Timer;



  public class ch22ex6 extends Sprite {
    public function ch22ex6()
    {
      var timer:Timer = new Timer(1000);
      var nyc:LocalClock = new LocalClock(timer, "New York City, USA", -5);
      var paris:LocalClock = new LocalClock(timer, "Paris, France", 1);
      var tokyo:LocalClock = new LocalClock(timer, "Tokyo, Japan", 10);
      addChild(nyc);
      nyc.x = 0;
      addChild(paris);
      paris.y = 50;
      addChild(tokyo);
      tokyo.y = 100;
      timer.start();
    }
  }
}

import flash.utils.Timer;
import flash.events.*;

import flash.display.Sprite;
import flash.text.*;


class LocalClock extends Sprite {
  private var location:String;
  private var timezoneOffset:int;
  private var labelTF:TextField;
  private var clockTF:TextField;
  
  public function LocalClock(timer:Timer, location:String, tzOffset:int) {
    this.location = location;
    this.timezoneOffset = tzOffset;
    labelTF = new TextField();
    clockTF = new TextField();
    labelTF.autoSize = clockTF.autoSize = TextFieldAutoSize.LEFT;
    labelTF.width = labelTF.height = clockTF.width = clockTF.height = 0;
    labelTF.selectable = clockTF.selectable = false;
    labelTF.defaultTextFormat = new TextFormat("_serif", 12, 0, false, true);
    clockTF.defaultTextFormat = new TextFormat("_typewriter", 12, 0x6AF685);
    clockTF.background = true;
    clockTF.backgroundColor = 0x000000;
    labelTF.text = location;
    clockTF.y = labelTF.textHeight + 5;
    addChild(labelTF);
    addChild(clockTF);
    timer.addEventListener(TimerEvent.TIMER, onTimer);
  }
  
  private function onTimer(event:TimerEvent = null):void {
    var date:Date = new Date();
    date.hoursUTC += timezoneOffset;
    clockTF.text = pad(date.hoursUTC) + ":"
                 + pad(date.minutesUTC) + ":"
                 + pad(date.secondsUTC);
  }
  
  private function pad(n:Number):String {
    var s:String = n.toString();
    while (s.length < 2) s = "0" + s;
    return s;
  }
}