I’m John C Bland II

Husband, Father, Tech Author, Deacon.
Founder of Katapult Media, and full-stack polyglot developer.
Political Free Agents Podcast Host.

I create. I launch.

YouTube Channel

I post regular fun on YouTube like me playing the bass and anything else I find fun. 

Get Something Built

All project work goes through Katapult Media. Business is open. Let’s chat.

Join me for “Adobe Flex Development Primer” Session

My good buddy Guillermo (gman) asked me about some Flex info. He’s a solid PHP’er and said he wanted to get into Flex so I hit him back with some info on where to get started. I also, as I typically do, jumped on the opportunity to do a Connect session to help him ramp up. Last time I did this for a friend it was one on one. This time…I’m opening it up to the public.

Session Description
The Flex Dev Primer is a pure development session (don’t expect theory and graphics although you might get some) focused on helping non-flex developers ramp up to become comfortable with Flex in a short period of time. We will focus on Flex 3/Halo but will spend the last while discussing the shift in Flex 4/Spark.

This session will be recorded.

Connect URL
https://experts.na3.acrobat.com/flexdevprimer/

Session Details
Date: 7/13/2009
Time: 8-9 PM CST

I’ve updated my speaking calendar with the details. I will keep it updated regularly with any and all of my engagements as well as any changes to this session.

AS3: Converting Date() to the Epoch

The Flash Player uses the same epoch as Unix (January 1, 1970). An epoch is “a particular period of time marked by distinctive features, events, etc.” (source: Dictionary.com)

One thing to note is the date pertains to the UTC (univeral time coordinated: “Universal time, taking into account the addition or omission of leap seconds by atomic clocks each year to compensate for changes in the rotation of the earth.” [source: Dictionary.com]). Flash can handle this just fine. Let’s get to the code (starting to itch with all of these definitions).

One option to get the UTC date:

var now:Date = new Date();
var epoch:Number = Date.UTC(now.fullYear, now.month, now.date, now.hours, now.minutes, now.seconds, now.milliseconds);
trace(now, epoch/1000, Math.round(epoch/1000));

The only real thing to note is the epoch/1000 is there because Flash uses milliseconds and epoch is in seconds so we divide by 1000 to get the seconds since the epoch. Now, that is how I first did it until I RTFM (read the freaking manual). It felt so dirty and unnecessary. Here is the easiest way to do it.

var now:Date = new Date();
var epoch:Number = Math.round(now.valueOf()/1000);
trace(now.valueOf(), epoch); //1238595716133 1238595716

Notice the first trace shows a lot more numbers since it is milliseconds since the epoch. The second number is the epoch/1000 and rounded. Don’t forget to round or you’ll get three decimal places. Date.value() is the trick here. By definition: “Returns the number of milliseconds since midnight January 1, 1970, universal time, for a Date object.” (source: Adobe LiveDocs)

Anyways…that’s it. No need to pontificate (been wanting to use that word; lol) anymore about such a simple task.

UPDATE

Since someone on Twitter made the statement about getTime() I guess I wasn’t clear. Let me clarify.

The above is NOT the only way to do it. Yes, you can use new Date().getTime() or new Date().time (preferred over getTime() since it really is a property). They both yield the same result as new Date().value(). Dividing by 1000 and rounding is still required since we’re still fooling with milliseconds since epoch.

Thanks.

Flex 3: Setting List component itemRenderer

In MXML you can easily set the itemRenderer to the string of your class, including dot syntax classpath, but in ActionScript it is different.

_list = new List();
_list.itemRenderer = new ClassFactory(IndexRenderer);
addChild(_list);

As you see the ClassFactory class is used because itemRenderer expects an IFactory implementation.

Just a quick tip.