Snippet – Converting yyyy-mm-ddThh:mm:ss.mssZ to Date()

Hi,

So, in dealing with the Google Data API most dates use the format above. Here is a regular expression to decompose it:

1
2
3
4
5
6
7
8
9
10
11
12
13
var date:String = "2010-12-12T09:54:35.002Z";
 
var exp:RegExp = /(\d\d\d\d)([- \/.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])T([0-2][0-9]):([0-5][0-9]):([0-5][0-9]).([0-9]{3})Z/i;
 
var res:Object = exp.exec(date);
 
// year res[1]
// month res[3]
// day res[4]
// hour res[5]
// minute res[6]
// seconds res[7]
// milliseconds res[8]

Now remember that the constructor for the Date object is quite a pain. It considers Januaray to be month 0, and the first day of the month to be the zero’th day of the month.. With this in mind, you can construct the Date object.

1
var time:Date = new Date(res[1], res[3] - 1, res[4] - 1, res[5], res[6], res[7], res[8]);

Now, switch to the time-zone of the user..

1
time.minutes -= time.getTimezoneOffset();

That’s it folks!

Sample Code – Using the YouTube AS3 API with the YouTube Player API

Hi Everyone,

I have been absent for a while.. taking advantage of life. I also have switched to Android lately, doing some prototyping work with 80/20 Studio in NYC.

Someone from Belgium contacted me today about the YouTube AS3 API, so I decided to look into it once again. While browsing the Youtube API site I found that they have finally published a AS3 Player that can be used!! So here is some sample code on how to do it.

Continue reading

Tutorial – Creating a reusable Slider Control / Component

Hi Everyone,

Today I will cover the subject of creating a reusable slider control which takes two bitmaps as resources. The thumb bitmap will slide on the rail bitmap. It is a very simple concept!

We will basically take this image:
and this one:
and make this (try it, move that knob):


In fact, the code you are about to write will take ANY two images and create a slider with them. Just like magic, as long as your images make some sense ( a track and a button ), it should be golden!

Starting Point
When I started writing this tutorial, I was still using the Flash IDE; but since then I am free!! I now use exclusively FlashDevelop. With that in mind, the package to start the coding, if you want to follow along is here. You will need FlashDevelop & the Flex SDK 3.4 or newer.
Continue reading

Tutorial – Multi Touch in AS3 / Flash Player 10.1 – Part 2. TouchEvent & MouseEvent Sequences

Hi Everyone,

In this installment I will cover the TouchEvent and how it is intertwined with MouseEvent. First you need to understand that touches will fire MouseEvent‘s too. You will get a TouchEvent first, then a MouseEvent. This can prove annoying in some cases, and good in others.

For the complete listing of TouchEvent‘s as well as some basic description of the information it carries please refer to this page.
Continue reading

Tutorial – Multi Touch in AS3 / Flash Player 10.1 – Part 1. Setting Up

Hi Everyone,

I had the pleasure, although it was a strenuous experience, to work on Adobe Post. It is still a private project; undertaken by 80/20 Studio in NYC on behalf of Adobe. It was demonstrated (shortly) by Kevin Lynch at the Adobe MAX conference on Oct 14th, 2009. It implements one of the nicest new features of Flash Player 10.1: Multi-Touch.

Continue reading

TubeGripClient – Play Any Movie on YouTube in AS3 with your own player!

Hi Everyone,

as some of you might have noticed, KeepVid went downhill. I don’t know exactly when, however I found an alternative: http://www.tubegrip.com. It works pretty well…

Here is a sample use of this library:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public function startTest():void
{
	_client = TubeGripClient.getInstance();
 
	// this takes a url from YouTube they call Watch Urls.. basically, the url you get when you try
	// to share a video with a friend...
	_client.getFLVUrl("http://www.youtube.com/watch?v=WPzgGs_cHWo");
	_client.addEventListener(TubeGripEvent.URL_READY, doUrlReady);
	_client.addEventListener(TubeGripEvent.REQUEST_FAILED, doRequestFailed);
}
 
protected function doUrlReady(evt:TubeGripEvent):void
{
	trace("urls are:");
	trace("[flv] " + evt.flvUrl);
	trace("[hd] " + evt.hdUrl);
	trace("[hq] " + evt.hqUrl);
}
 
protected function doRequestFailed(evt:TubeGripEvent):void
{
	trace("request failed.. for whatever reason");
}

Continue reading

Tutorial – Consuming REST web services in ActionScript 3 – Part 4

Hi Everyone,

this is a follow-up to the following posts:

In this post, I will add code to identify each request uniquely, give you a class called “AbstractClient” that will handle most of the mechanics and is easily extended. The idea is to give you a base on which to build. Essentially, for every service call you will want to make you will need 2 functions:

  • A public function that will send the request out
  • a protected function that will receive the response, digest it and dispatch an event

For those who’d like to go ahead and enjoy the goods right away, I will write this tutorial so it can be read and understood on it’s own.

Continue reading

Tutorial – Playing FLV video in plain AS3 – Part 4 – Sample Usage

Hi Everyone..

This is the fourth (and most probably the last) installment of this series on playing FLV (and H.264 MP4) video in Flash from scratch.

Full source code for the library is here.

The related posts are:

For many of you, this might be the only post you are interested in. It will show you how to use the library.

Continue reading

Tutorial – Playing Video with SubTitles in AS3 – Part 1

Hi Everyone,

The series on Playing FLV files in AS3 was probably the most popular post on this blog. So I thought I would take it one step further: show SubTitles from an .SRT file over the FLV while it is playing.

First, you need to read this post by Jankees van Woezik. He did a great job at making a SRT parser, although; well, I wouldn’t convert everything right away but rather do it on-demand; but that is a small detail.

Then you need to find yourself a SRT file. There are plenty on the internet, I took the Star Wars subtitles, changed the time a little bit, and ended up with this SRT file.

The video I chose I got using TubeGrip, it is basically a Telemark skiing video, which I love and miss. This video is a mp4 format using H.264 codec, which is supported by Flash Player 10 and over. Much more pretty. You can get those from TubeGrip off YouTube.

Continue reading

SWF TextField Factory — Dynamically Loading Fonts in AS3 using Flex SDK 3.4

Hi Everyone,

it has been a long while since I wrote! Been busy. Now I have some time and the first thing I did is to get away from the Flash IDE completely. I had been waiting to be able to debug directly in FlashDevelop for a while, tried some extension that didn’t work, then Philippe did actually fix another one and it works beautifully. You can find the link here, look for Version 0.9.7 at the bottom of the first post. Unzip into your FlashDevelop plug-ins folder, restart FlashDevelop and bravo!

So I am Flash IDE Free!! Woohooo. Then the first thing I wanted to master is the Preloader, and FlashDevelop has a very nice “AS3 with Preloader” project template. It is very easy to work with. Very beautiful.

Now the next challenge, loading fonts dynamically. Euh, well, I used to do it from a FLA, was easy. But using the Flex SDK 3.4 it seems that some things changed. After HOURS of playing around, I ended up with the following system:

  • embed the font inside of a swf that contains a Main class + the font class
  • create a function that will spawn textfields already using the font inside this Main class

Although this system has some limitations, it works beautifully.

Continue reading