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

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

YouTube AS3 API link..

Hi everyone,

I had all but forgotten about this post on the official Youtube docs.. I will spend some time in the near future on the API to clear up some confusion and write more examples; plus finish the implementation of the interactive part of the functionality.

In the meantime, here is the link to the article… http://code.google.com/apis/youtube/articles/youtube_actionscript3.html

:)

Martin

Tutorial – AS3 & REST web services with RESTProxy – Part 1

Hi Everyone,

[UPDATE Jan 19th, 2008]
I’ve just modified RESTProxy.php to handle gzip encoding from the client-side. It was quite simple. I was trying to consume web services on Discogs.com and it requires that you accept gzip encoding..

a while back, almost a year ago now, I published a little package of code called RESTProxy. This proxy is accessed from Flash AS3 code through AMFPHP to process HTTP requests otherwise not possible because of cross-domain limitations or because flash.net.URLLoader doesn’t allow the operation. True in Flex you have HTTPService which allows you the full spectrum of REST web service calls, however not so in flash.

In this tutorial I’ll cover when to use RESTProxy, guide you through it’s installation then show you a few examples.

URLLoader vs. RESTProxy

The following chart explains the advantages of using RESTProxy over URLLoader.

RESTProxy versus URLLoader

However, it is possible all you want is to consume webservices using POST and GET, on a host with a valid cross-domain.xml file; in which case you do not need RESTProxy. I developed RESTProxy to consume the more advanced data services from the YouTube GData Web Services.
Continue reading

AS3 – RealNetworks Rhapsody Web Service – Artist Search

Hi Everyone,

A few years ago Real Networks launched some webservices that you can use to find artists, tracks and the like. Although their license is quite limiting, you can view their SDK Documentation here: http://webservices.rhapsody.com/rwssdk/rwssdk_v1_5.pdf the main website being here: http://webservices.rhapsody.com/.

Continue reading

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

Hi Everyone,

This is the third installment of the series, you can find the first two here:
Part 1 – http://blog.martinlegris.com/?p=87
Part 2 – http://blog.martinlegris.com/?p=90

Today I will develop on the data handling once the data is received from the webservice calls.
I will describe some methodologies I’ve developped that help mainstream data handling by using custom data types to hold the data, and custom iterators to access these data, and custom event types to transport the data.

Starting Point

In the last tutorial, we had a Singleton class calls WSClient which ran the request for us, then dispatched an event once the xml data was received.
Continue reading

Getting around AS3′s un-RESTful-ness

Hi Everyone,

[UPDATE Jan 19th, 2008]
I’ve just modified RESTProxy.php to handle gzip encoding from the client-side. It was quite simple. I was trying to consume web services on Discogs.com and it requires that you accept gzip encoding.. The source has been modified.

Mise en situtation
for those who have been following the development of the AS3 Youtube Data API library development, you might have seen that I hit a serious wall when I tried doing PUT and DELETE requests using flash.net.URLRequest together with flash.net.URLLoader. Simply put, it is impossible to execute such requests directly from the code library provided in Flash CS3. Some people have been trying to get around the problem using raw sockets, but will hit another wall inevitably: you are only allowed to connect raw sockets to the host that served you the .swf file. Hence, impossible to connect to gdata.youtube.com.

I had another idea, using Flex’s HTTPService inside of code compiled using Flash CS3. Hit another wall there. You can dynamically load some of Flex’s classes, like StringUtil, for example, using a Loader + the applicationDomain to get a reference to the Classes embedded in a SWF then instantiating them; but it doesn’t work on my complex Flex classes. You get weird errors, which I don’t understand. After spending a day on that, I decided it was over.

My goal was to keep this library client-side, AS3 only. I didn’t mind loading a SWF to get some of it’s classes, but I didn’t want to use a proxy on a server… and well, it can’t be done.

In comes the proxy
The idea is to provide a very general, generic proxy to help AS3 become RESTful. I had a few ideas, and in the end decided to opt for AMFPHP because of my past experience with it, and the fact that since Patrick Mineault (who has been a friend here in Montreal) has left, it seems it doesn’t get much attention. AMFPHP now talks AMF3, which I think is pretty cool.
Continue reading