Example Name: DebugFunctions.java
Language: Java
Version: 1.0.0
Code:
package com.oreilly.frdg;
import flashgateway.io.*;
import java.util.*;
import java.lang.*;
import java.io.Serializable;
public class debugFunctions{
public debugFunctions(){
}
public ASObject computeTimeDifference(ASObject t) {
Date d = new Date();
// Pull the ActionScript date object out of the argument
Date e = (Date)t.get("date");
// Get the difference between the dates
double difference = (double)e.getTime() - (double)d.getTime();
int days = (int)(Math.floor(difference/1000/60/60/24));
difference -= days*1000*60*60*24;
int hours = (int)(Math.floor(difference/1000/60/60));
difference -= hours*1000*60*60;
int minutes = (int)Math.floor(difference/1000/60);
difference -= minutes*1000*60;
int seconds = (int)Math.floor(difference/1000);
difference -= seconds*1000;
int milliseconds = (int)difference;
String daysStr = String.valueOf(days);
String hoursStr = String.valueOf(hours);
String minutesStr = String.valueOf(minutes);
String secondsStr = String.valueOf(seconds);
String millisecondsStr = String.valueOf(milliseconds);
// Pack the date parts back into the ActionScript object for the return
t.put("days", daysStr);
t.put("hours",hoursStr);
t.put("minutes",minutesStr);
t.put("seconds",secondsStr);
t.put("milliseconds",millisecondsStr);
// Return the original ASObject with new properties
return t;
}
}
Download code text
Download chapter example files