Thursday, March 6, 2008

Getting TwitterCamp to work with AIR 1

When I was at the 360Flex Atlanta conference they had TwitterCamp running on a few large flat screens. I still don't get Twitter but it was cool to watch the bubbles changing as people put in their tweets.

I can't remember what people were saying but I think it's pretty funny that I was watching people tell me what they were doing at 360Flex on a monitor that was at 360Flex. They were probably saying they were at 360Flex.

Today I was trying to find a Flex Twitter app. I found AirTalkr and TwitterCamp. Neither of them work. AirTalkr is supposed to hook into Twitter but I could not figure out how. At least it's not obvious. TwitterCamp does not work with the production AIR 1 release.

I think TwitterCamp is cool and I would like to run it, now... I decided to download the source for TwitterCamp and update it to work with AIR 1. Then I thought this would be a great thing to Blog about so here goes...

I downloaded the TwitterCamp source from Daniel Dura's blog at:

http://www.danieldura.com/code/twittercamp/

I copied the zip file to C:\Download\AIR and then unzipped it to C:\Download\AIR\twittercamp

I then created a new Flex AIR application in Flex Builder 3 and named it TwitterCamp.

I copied the files in the C:\Download\AIR\twittercamp source root directory to to the TwitterCamp\src directory.

The project wouldn't build because I had accepted the default source directory of TwitterCamp\src. I fixed the problem by moving the files from TwitterCamp\src to TwitterCamp.

Then I had another build problem because com.adobe.utils:DateUtil could not be found.

I followed a link to the source code that was in one of the comments but it turned out to be a broken link.

I Googled com.adobe.utils.DateUtil and eventually found:

http://code.google.com/p/as3corelib/downloads/list

I downloaded corelib-.90 and expanded it to:

C:\Program Files\Adobe\corelib-.90

After adding C:\Program Files\Adobe\corelib-.90\corelib\bin\corelib.swc to the Flex 3 library path I then started getting:

Severity and Description Path Resource Location Creation Time Id
1119: Access of possibly undefined property window through a reference with static type flash.display:Stage. TwitterCamp TwitterCamp.mxml line 61 1204846931832 21


To fix the compiler error I changed

systemManager.stage.window.x = 10;
systemManager.stage.window.y = 10;

to

systemManager.stage.x = 10;
systemManager.stage.y = 10;

Then one more error was left:

Expected a single content tag in TwitterCamp-app.xml

I Googled "Expected a single content tag" and found a blog post that referred to a similar problem and explained how to fix it. The problem was caused by the app.xml being different in AIR 1.0

To figure out what changes I needed to make to TwitterCamp-app.xml, I created a new AIR project named TwitterCampTest and compared TwitterCamp-app.xml to TwitterCampTest-app.xml.

I changed

http://ns.adobe.com/air/application/1.0.M4

to

http://ns.adobe.com/air/application/1.0

I then started adding XML elements one by one until the compile errors went away.

I added:

the id, filename, version and initialWindow tag. For the id and filename tags I also changed TwitterCampTest to TwitterCamp.

I tried debugging and got the following error:

[SWF] TwitterCamp.swf - 1,148,762 bytes after decompression
Error: Error #2071: The Stage class does not implement this property or method.
at Error$/throwError()
at flash.display::Stage/set x()

I fixed this by commenting out the following statements:

//systemManager.stage.window.x = 10;
//systemManager.stage.window.y = 10;

note that I added .window back to the statements.

I ran the app but it didn't look good on my laptop screen. It was too big. I changed the stageHeight and stageWidth to:

systemManager.stage.stageWidth = 800;
systemManager.stage.stageHeight = 600;

Now it all works!

It looks cool but I'd like to customize it so it says AIR instead of Apollo, etc... Stay tuned.

I have posted the code to:

http://www.riaplayground.com/download/TwitterCamp/TwitterCamp.zip

I also left a comment on Daniel's blog and let him know where the code is in case he wants to use it.

No comments: