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.

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.

Quick Posts Coming…

So I’ve been Twittering (https://twitter.com/johncblandii) a lot lately, as usual, and I noticed I tend to Twitter my dev’ thoughts more than blog them. I want to get back to blogging them so this is an FYI.

You will see some quick posts here soon. By quick I mean random things I figure out or discover while developing or quick posts about dev approaches, design patterns, or whatever. I’ll still get a meaty post in here at times but you’ll see quicker posts here/there.

Flex 3 Remoting one coming in a second. ๐Ÿ˜‰

Upcoming Training Topics

I have a few suggestions on training desires and I’m pretty stoked about doing them.

  • Flex+LCDS+CF: A Sexy Relationship (preso will be for AZCFUG)
    Many Flex dev’s from back in the day loved AMF integration in CF. It seriously was the fastest way to get up and running but there is a newer, much sexier way to pull your data: LiveCycle Data Services. This is native to ColdFusion 8 and it even boasts some sweet features you can’t easily/quickly accomplish in regular CF-AMF.
  • Flex Development for .NET Developers
    I’ll utilize WebORB here to show a REALLY sexy integration point between Flex and .NET. General integration using web services will be shown as well but that isn’t nearly as sexy as WebORB. ๐Ÿ˜‰ Along with data integration I’ll discuss the comparisons between Flex dev’ and .NET dev. You may even hear the word XAML in there somewhere. ๐Ÿ˜‰
  • Flex/PHP Integration
    You will see data integration between Flex and PHP using AMFPHP. Since I love CodeIgniter so much, and if time allows, I might show how you can integrate a Flex app in a PHP site based on CodeIgniter.
  • ActionScript 3 Series
    • The Basics
      This may be a short preso but it will cover the basics of using AS3. I’ll discuss a few things specific to Flash CS3/CS4 and a few about Flex 3. This will also cover utilizing classes so don’t expect to see anything on a timeline, literally.
    • “Patternization”
      I’m a fan of design patterns and I’ll show how you can implement a few. There won’t be a laundry list of patterns discussed but I will cover a few of my fav’s.

These aren’t in any specific order. I’ll iron out a schedule here soon. For sure I’m doing 2 trainings a quarter but which two I’m not sure about yet.

More coming soon.

Free “Training” – What do you want to learn?

I’m going to start my “community service” by doing a series of presentations (via Adobe Connect). They will range from quick (15 minutes) to long (1 hour) and will cover a range of topics. I’m open to talk about a wide array of topics but I would like to know what you want to see.

Along with the above preso’s I’ll be doing a preso for AZCFUG one of these upcoming months. The talk will be over Flex+LCDS+CF. More info about that later.

BTW, all sessions will be recorded and I’ll add them to my Preso’s page once they are completed.

So, post a comment below and I’ll compile a list and pick/choose to create a schedule.

Thanks.

Accepted in Adobe Community Expert program

Yep, I’m accepted and STOKED! ๐Ÿ™‚ I won’t get long winded but…

4 score and 7 years…{hrmm, clears throat}…wrong speech. ๐Ÿ˜‰

Seriously, I’m excited and happy to be accepted in such a great program. I look forward to learning more about it and continuing my “community service” as I did when I was a UG manager.

Special thanks to Rachel Luxemburg and Sarge.

Use dynamic xml namespaces

Let me start by saying the move to AIR 1.5 was NOT(!!!!) an easy task. For whatever reason my entire app acted different than it did in 1.0. I don’t know why but it did. Maybe it is more of a Flex 3.2 issue…not sure. Either way, I’m working through a ton of odd, post-upgrade bugs. One of them existed in an old version of the AIR Remote Updater classes. I almost scrapped it and wrote my own but figured I’d look into the source and see if it is an easy fix. Well, it was. It is a simple issue of a hard-coded namespace.

(more…)

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.