Experimenting with new Adobe Social service library

November 3rd, 2009 by Slav

Adobe has recently unveiled their new social media library on Labs. It is a framework that allows user to connect to a several popular social media networks at once and get the information from the users profile, get a friends list, post updates, post news items etc… All in all pretty useful stuff. To get acquainted with this framework I made a little demo app that connects to twitter and facebook, get user’s profile info, enables to send simultaneous status update, and gets a list of friends.

 Social network demo

Here are some of the things I noticed when playing with the package:

 Pros:

+ easy to implement (you don’t have to worry about parsing json, knowing REST api’s , authentication, asynchronous javascript loading / responses.. all of it is done behind the scenes for you.

+ easy to use :  The actual API itself is quite simple event based, not too many commands and parameters..

+ small in size : The file you need to embed (that acts as a framework proxy) has only about 9K!

Cons:

- reliability : This might be due to the fact this is still only a technology demo, or a connectivity issues, but I experienced quite a few connection problems (especially to a twitter api)

- features : Some things are not implemented (at least I didn’t see them). Like for example to get user’s last status update. You can change it / set it , but not get it ? Maybe this will be implemented later.. Or to get a news feed from Facebook.

 - strong typing of returned value objects : This bugged me quite a bit. You get a Response object for example that contains a several value objects such as User, Identity etc.. These objects doesn’t exist in the AS3 (client side of framework) though, although they probably exist as a typed value objects in PHP or some back-end language..(I saw them strongly typed in Flex debugger) So you have to code against a documentation, or create your own client side version of these objects (if you have time)..

 - authentication in separate html windows : there isn’t a way (or at least I didn’t see one) how to pass a user authentication data to a social network so you can log him/her automatically. The way it happens is that the new html window opens the user types in his/her login and then you get a callback and the new windows / tabs try to close automatically. This is a bit awkward, it would be much better if we could login user automatically and have a login interface in flash/flex once and then remember users login data (perhaps in SharedObject) and don’t ask for it every time he/she needs to connect..

Overal, despite couple of small problems, it’s seems like a great step forward to a unified share networks API that was till not virtualy non existant for a flash developers!

Posted in AS3, Flex, flash | 2 Comments »

AttachMovie in AS3 ? Now possible! (also attachBitmapData ;)

November 2nd, 2009 by Slav

I code in AS3 for quite a while now, and don’t get me wrong, I do love it and I NEVER want to go back to as2.

However; there are some things I wish remained in AS3 that were possible to do in AS2.

Things like “eval” and “attachMovie” comes to mind…

Why attachMovie ? Isn’t it perfectly possible to do addChild(new WhatewerClass()) ?

Yes and no. The problem is if you don’t develop in Flash IDE, but in more sophisticated code editors like FDT, FlashDevelop or Flex.

Let’s say you have a graphical asset sitting in your library, it needs no interactivity so you don’t create any class for it. It simply extends MovieClip and has a linkage name “Asset1″ assign to it.

Now the moment , in your code you decide to attach it to your display container via addChild(new Asset1())none of the code editors I mentioned above will know about Asset1 as that Asset1 is a class created by flash IDE only when the fla is being compiled and therefore is only available during runtime. So they will mark it as erroneous class reference. Of course , swf will compile just fine, but that’s not the point :) You don’t want to have your project covered in errors of some of which are not really error and need to remember which ones are not real.. !

There are several solutions to this of course.

One I used, is to compile swc from the fla, so the every linked library assets are available to FDT/flash develop/flex for reference. The trouble with this solution is you have to keep the swc file updated which isn’t always straightforward.. For example flex sometimes doesn’t pick up that swc have been changed, you have to delete swc and then re-publish it to force it to recognise change. Similar situation happens with FDT sometimes. As well as you can into a situation where you get into a sort of a recursive error cycle , where swf doesn’t compile correctly because compiling that swf requires some assets from swc that aren’t there yet because project’s swc doesn’t have that assets yet because it can’t be compiled before the project doesn’t have those errors..  

The solution I devised instead is much simpler and mimic the old as2 “attachMovie” functionality.

Taking advantage of built in “getDefinitionByName” command from flash.utils package we can turn the asset into a class by giving it it’s linkage ID . As that class is compiled into swf it will be available during runtime - so that will work fine.

During authoring time it won’t flag up as error as well as it’s typed correctly to MovieClip (so sprite will work as well).

So I wrote a wrapper utility class that has 2 functions :

attachMovie - expect a linkage name and returns a MovieClip instance
attachBitmapData - expect a linkage name and returns BitmapData

this is a code for attaching the library assets used in the demo bellow :

  private function attachAsset1():void
  {
   var asset1:Sprite = MCUtils.attachMovie("Asset1");
   asset1.x = 10;
   asset1.y = 8;
   this.addChild(asset1);
  }
 
  private function attachGirl():void
  {
   var girlBmp:BitmapData = MCUtils.attachBitmapData("Girl");
   var girlBitmap:Bitmap = new Bitmap(girlBmp);
   girlBitmap.x = 10;
   girlBitmap.y = 85;
   this.addChild(girlBitmap);
  }

Demo :

Attach Movie Zip

Posted in AS3, FDT, Flex, flash | 9 Comments »