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

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

Should we start learning Javascript once again?

Hi Everyone,

with HTML 5 being adopted by more and more browsers out there, with DailyMotion releasing an HTML5 version of the movie profile page, and YouTube doing the same; there comes a question: should I get back to learning Javascript?

The posts on the subject abound all over the internet:

HTML 5 versus Flash / Flex

Adobe was heard saying:

It might be a decade before HTML 5 sees standardization across the number of browsers that are going to be out there (…)

Right.. I think it will take 2 years. I think in 2 years, you better get really good with the Google Web Toolkit if you want to be on the cutting edge. Otherwise, you can wait 4-5 years. And who will save our jobs: Microsoft. By being the shittiest browser out there, Internet Explorer will help keep the value of actionscript knowledge high for atleast another 2 years.

That is my take. What is yours?

:)

Martin

Study – The Video Players of Social Networks (YouTube, DailyMotion, Veoh, Vimeo, GoogleVideo, Flickr)

Hi Everyone,

I am doing research on which video player I can easily embed inside of an AS3 application. I had these players in mind: DailyMotion, Vimeo, Veoh, Youtube, GoogleVideo, and the DivShare player as a fallback. Right of the bat, the following players are still in AS2:

  • YouTube
  • DailyMotion
  • DivShare
  • GoogleVideo

While these are in AS3:

  • Vimeo
  • Veoh
  • Flickr

Continue reading