Alain Hufkens {Rich Interactive Applications Developer}

14May/093

Retrieve Basecamp data with BasecampAS3Lib

One of the projects I am currently working on is an open source Actionscript library that wraps the Basecamp REST API in an easy to use AS3 classes. The project is called BasecampAS3Lib an can be found on Google Code. The project is still in development and I did some serious refactoring yesterday.

At this point the services can only retrieve data from Basecamp and you can already experiment with the ProjectService, CategoryService and TodoListService classes. The other services still need to be implemented. But this post will give you a sneak peak on how simple it can be to retrieve data (in this case project data) from Basecamp with this lib.

NOTE: This code only works in an Adobe AIR application (see below for more details why).

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
  xmlns:mx="http://www.adobe.com/2006/mxml"
  xmlns:basecamp="net.hufkens.basecamp.*"
  xmlns:services="net.hufkens.basecamp.services.*"
  layout="absolute"  viewSourceURL="srcview/index.html">
 
  <mx:VBox width="100%" height="100%">
    <mx:HBox width="100%">
      <mx:Label text="url:"/>
      <mx:TextInput id="apiurl" width="100"/>
      <mx:Label text="username:"/>
      <mx:TextInput id="username" width="100"/>
      <mx:Label text="password:"/>
      <mx:TextInput id="password" width="100"/>
      <mx:Button label="get projects"
        click="getProjects()"/>
    </mx:HBox>
    <mx:DataGrid dataProvider="{projects}"
      width="100%" height="100%"/> 
  </mx:VBox>
 
  <basecamp:BasecampAPI id="api"
    url="{apiurl.text}"
    username="{username.text}"
    password="{password.text}"/>
 
  <mx:ArrayCollection id="projects"/>
 
  <mx:Script>
    <![CDATA[
      import net.hufkens.basecamp.events.BasecampEvent;
     
      private function getProjects():void {
        api.projectService.addEventListener(
          BasecampEvent.GET_LIST, handleGetList);

        api.projectService.addEventListener(
          BasecampEvent.FAIL, handleFail);

        api.projectService.getList();
      }
     
      private function handleGetList(event:BasecampEvent):void {
        projects = new ArrayCollection(event.data as Array);
      }
     
      private function handleFail(event:BasecampEvent):void {
        Alert.show(event.data as String);
      }
     
    ]]>
  </mx:Script>
 
</mx:WindowedApplication>

However there is still an issue with the authentication. Apparently using basic authentication from a Flash/Flex application is not that trivial as it would sound. A while ago I wrote a blog post about this (read it here), but this approach only works when you run it from an AIR application. The same code doesn't work when running from a url on a web site.

So, if you have any suggestions or a solution for the basic authentication issue please let me know.

Filed under: air, flex 3 Comments
1Feb/093

Useful Actionscript libraries on Google Code

code_smI recently discovered the Starred Projects feature in Google Code. As a developer I don't want to write everything myself because there is already so much out there. The following list contains libraries that every Actionscript developer doing Flex should be aware of their existence:

  • antennae: Templates for building complex Flex projects with Ant. I have been using ANT for a while but have to check out this project to see if it can make things easier. It has been around for a while.
  • as3corelib: A must know library. The corelib project is an ActionScript 3 Library that contains a number of classes and utilities for working with ActionScript 3. These include classes for MD5 and SHA 1 hashing, Image encoders, and JSON serialization as well as general String, Number and Date APIs.
  • as3crypto: As3 Crypto is a cryptography library written in Actionscript 3 that provides several common algorithms. This version also introduces a TLS engine (TLS is commonly known as SSL.)
  • as3xls: Project that makes it possible to read and write Excel files in Flex. The example on the site does not work with my Excel file, but still it could come in handy.
  • as3yaml: as3yaml is an Actionscript 3 YAML 1.1 parser and emitter.
  • facebook-actionscript-api: The Facebook Actionscript API provides an interface between the Facebook REST based API and Flash/Flex based applications.
  • flash-thunderbolt: ThunderBolt is a logger extension for ActionScript 2 and 3 applications using Firebug. For logging without Firebug, especially for AIR applications, check out the ThunderBolt AS3 Console.
  • flex-object-handles: A very common UI element found in many applications are those little square handles around an on-screen object that allow you to move & resize it.
  • flexcairngorm: Extensions for the Adobe Cairngorm MVC Framework.
  • flexcover: Flexcover is a code coverage tool for Flex, AIR and AS3. It incorporates a modified version of the AS3 compiler which inserts extra function calls in the code within the SWF or SWC output file.
  • flexlib: The FlexLib project is a community effort to create open source user interface components for Adobe Flex 2 and 3.
  • flexundoredo: The Flex UndoRedo Framework provides all the facilities that you need for implementing undo and redo within your applications. The Framework can be used with or without Cairngorm.
  • gaforflash: This is an ActionScript 3 API for Google Analytics data collection.
  • openflux: OpenFlux is an open-source component framework for Flex which makes radically custom component development fast and easy.
  • papervision3d: Open Source realtime 3D engine for Flash.
  • swizframework: Swiz is a framework for Adobe Flex that aims to bring complete simplicity to RIA development. Swiz provides Inversion of Control, event handing, and simple life cycle for asynchronous remote methods. In contrast to other major frameworks for Flex, Swiz imposes no JEE patterns on your code, no repetitive folder layouts, and no boilerplate code on your development.
  • tweener: Tweener (caurina.transitions.Tweener) is a Class used to create tweenings and other transitions via ActionScript code for projects built on the Flash platform.
  • twitterscript: This is an ActionScript 3.0 library for accessing Twitter's APIs. This was originally code from Twitter, but it is being open sourced so it can be maintained and kept current.
  • urlkit: UrlKit supports Adobe Flex applications that need to expose URLs and window titles in the browser to represent their state. These URLs can be bookmarked, accessed via the Back button, etc.
  • wick3d: Wick3d is a 3D engine in progress for ActionScript 3 my colleague David Lenaerts who does some pretty amazing things :)

The order of this list is pure alphabetic and contains must know libraries and useful stuff that could come in handy in future projects.

Filed under: air, flex 3 Comments