A Simple hello class
that assigns a custom
message to a text field
based upon time of day.
**/
class com.bushidodeep.Hello {
   private var width:Number;
   private var height:Number;
   private var stageHeight:Number = 300;
   private var stageWidth:Number = 300;
   private var theDate:String;
   private var now:Date;
   private static var textFieldDepth:Number = 0;
   private var messageFormat:TextFormat;
   public var messageDisplay:Function = displayGreeting;
   public var message:String = "";

   // Movie clip that will contain visual
   // elements of the hello.
   private var container_mc:MovieClip;
   //
   public function Hello(target:MovieClip) {
       container_mc = target.createEmptyMovieClip("blah", 1);
       now = new Date();
       var timeNow =  formatTime(now)
       placeGreeting(timeNow);
   }
   private function placeGreeting(time) {
       messageFormat = new TextFormat();
       messageFormat.font = "Verdana";
       messageFormat.color = 0xffffff;
       messageFormat.bold = true;
container_mc.createTextField("messageText", textFieldDepth, 75, 100, 150, 25);
       container_mc.messageText.text = time;
       container_mc.messageText.border = false;
       container_mc.messageText.setTextFormat(messageFormat);
   }
   private function formatTime(theDate){
       var hour=theDate.getHours();
var minute=theDate.getMinutes()>9 ? theDate.getMinutes() : "0" + theDate.getMinutes();
       if (hour > 12){
           var timeString = (hour-12) + ":" + minute + "PM";
       }else{
           var timeString = hour + ":" + minute + "AM";
       }
       return timeString;
} }
}

Hi All,

In the following code my attempt at formatting the date returns this to the output window:
//
**Error** BushidoDeep:Users:chris:Desktop:hello:com:bushidodeep:Hello.as: Line 55: This statement is not permitted in a class definition.
         now = new Date();

**Error** BushidoDeep:Users:chris:Desktop:hello:com:bushidodeep:Hello.as: Line 56: This statement is not permitted in a class definition.
         trace ("The Time is " + formatTime(now));

**Error** BushidoDeep:Users:chris:Desktop:hello:com:bushidodeep:Hello.as: Line 61: ActionScript 2.0 class scripts may only define class or interface constructs.
     }

Total ActionScript Errors: 3      Reported Errors: 3
//
/**
A Simple hello class
that assigns a custom
message to a text field
based upon time of day.
**/
class com.bushidodeep.Hello {
    private var width:Number;
    private var height:Number;
    private var stageHeight:Number = 300;
    private var stageWidth:Number = 300;
    private var theDate:String;
    private var now:Date;
    private static var textFieldDepth:Number = 0;
    private var messageFormat:TextFormat;
    public var messageDisplay:Function = displayGreeting;
    public var message:String = "";

    // Movie clip that will contain visual
    // elements of the hello.
    private var container_mc:MovieClip;
    //
    public function Hello(target:MovieClip) {
        container_mc = target.createEmptyMovieClip("blah", 1);
        placeGreeting();
    }
    private function placeGreeting() {
        messageFormat = new TextFormat();
        messageFormat.font = "Verdana";
        messageFormat.color = 0xffffff;
        messageFormat.bold = true;
container_mc.createTextField("messageText", textFieldDepth, 75, 100, 150, 25);
        container_mc.messageText.text = messageDisplay();
        container_mc.messageText.border = false;
        container_mc.messageText.setTextFormat(messageFormat);
    }
//for testing only will use am/pm passed from formatTime() to output message
    private function displayGreeting() {
        if (now == "afternoon") {
            message = "Disco Rules";
        } else {
            message = "Samba Rules";
        }
        return message;
    }
    private function formatTime(theDate){
        var hour=theDate.getHours();
var minute=theDate.getMinutes()>9 ? theDate.getMinutes() : "0" + theDate.getMinutes();
        if (hour > 12){
            var timeString = (hour-12) + ":" + minute + "PM";
        }else{
            var timeString = hour + ":" + minute + "AM";
        }
        return timeString;
    }
    now = new Date();
    trace ("The Time is " + formatTime(now));

}
}




_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to