Archive for the ‘Actionscript 3’ Category

Google Web APIs – Actionscript 3 library (v2.1)

Google Web APIs – Actionscript 3 library (v2.1)



The library is a simple collection of Google’s API features, there is a class per feature, like Google Web search, Images Search, Google Suggest etc. Each library throws it’s own event with an Array or Value Object of matching datatype(s), for example GoogleWebItem, so it’s easy to keep track on wich data is recieved and what this data contains, giving the developer transparency using Intellisense.


This api contains:

  • Google Ajax API:
    • Google Search
      • Google Web Search
      • Google Images Search
      • Google Book Search
      • Google Video Search (Google Video & YouTube)
      • Google Blog Search
      • Google Local Search
      • Google Patent Search
      • Google News Search
    • Google Translation
    • Google Feeds
  • Google Weather
  • Google Suggest


This API is Flash & Flex compatible using Actionscript 3 (FP9 & 10).


You can find the documentation under downloads > documentation. It’s also archived in the downloadable source-zip (under the docs directory) and can also be found under the docs folder in the trunk of the SVN.

Little example code

var googleWebSearch:GoogleWebSearch=new GoogleWebSearch();,0,"nl");
googleWebSearch.addEventListener(GoogleApiEvent.WEB_SEARCH_RESULT,onWebResults) ;

//If you want to catch the API errors yourself:

private function onWebResults(e:GoogleApiEvent):void{
        var as GoogleSearchResult
        trace("Estimated Number of Results: "+resultObject.estimatedNumResults)
        trace("Current page index: "+resultObject.currentPageIndex)
        trace("Number of pages: "+resultObject.numPages)

        for each (var result:GoogleWebItem in resultObject.results){
                trace(result.title, result.url)

private function onAPIError(evt:GoogleAPIErrorEvent):void{
        trace("An API error has occured: " + evt.responseDetails, "responseStatus was: " + evt.responseStatus);


This library uses certain classes (for example JSON-decoding), found in the AS3CoreLib by Mike Chambers, Daniel Dura and Christian Cantrell. These classes can be checked out or downloaded here:


If possible, checkout the latest source via SVN. SVN Clients I would recommend:

Latest changelog

Changelog 2.0.2 to 2.1

  • API core: GoogleAPIServiceURL; All API URLs are now collected in this new class, this for maintenance purposes.
  • API core: GoogleApiKeyStore; removed a private function & added new keyIsSet getter
  • Search APIs: GoogleImageSearch: added 2 parameters to search() function; imageColor and restrictToDomain; imageColor is added between colorization and imageType; so beware, FUNCTION SIGNATURE HAS CHANGED
  • Search APIs: GoogleWebSearch: added 6 new parameters to search()-function; safeMode, LanguageRestrict, duplicateFilter, countryCode, customSearchEngineID, customSearchEngineRef
  • Search APIs: GoogleLocalSearch: changed parameter centerPointOfSearch in search()-function from type String to type Point
  • Global: removed string concatenations when building URLs, replaced them with URLVariables
  • Global: minor bugfixes


SVN Location

Tags: , ,

Categories: Actionscript 3, Library

As3 Crypto


Tags: , ,

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.)

  • Protocols: TLS 1.0 support (partial)
  • Certificates: X.509 Certificate parsing and validation, built-in Root CAs.
  • Public Key Encryption: RSA (encrypt/decrypt, sign/verify)
  • Secret Key Encryption: AES, DES, 3DES, BlowFish, XTEA, RC4
  • Confidentiality Modes: ECB, CBC, CFB, CFB8, OFB, CTR
  • Hashing Algorithms: MD2, MD5, SHA-1, SHA-224, SHA-256
  • Paddings available: PKCS#5, PKCS#1 type 1 and 2
  • Other Useful Stuff: HMAC, Random, TLS-PRF, some ASN-1/DER parsing

The library is offered under the BSD license, and include several derivative works from Java, C and javascript sources. Check the LICENSE.txt file for a list of contributors.

You can look at a demo of the functionality of the library. It’s built with Flex 2. It includes a unit test tab, and a benchmark tab.

This is what the benchmark tab outputs on my computer (Athlon64 2Ghz):

The 'numbers' are in 1000s of bytes per second processed.type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
md2                  1.01k        3.64k       15.08k       53.89k      171.76kmd5                221.85k      447.32k      739.54k      893.72k      905.82ksha1                82.28k      184.78k      286.76k      336.03k      345.41ksha224              60.84k      125.67k      200.27k      234.28k      247.58ksha256              60.52k      126.30k      199.19k      234.04k      246.01khmac-md5            48.37k      159.37k      282.87k      295.15k      341.21khmac-sha1           18.29k       64.82k      165.72k      277.60k      342.52khmac-sha224          5.75k       24.84k      125.71k      204.35k      256.36khmac-sha256         15.10k       49.33k      123.71k      206.17k      249.08krc4                117.24k      381.34k      878.93k     1315.01k     1539.44kxtea-cbc             2.49k        6.48k       12.80k       33.00k       44.48kaes128-cbc           1.61k        4.01k       22.97k       78.55k      205.01kaes192-cbc           1.34k        5.13k       20.91k       69.45k      172.43kaes256-cbc           1.48k        5.63k       18.87k       63.45k      150.39kblowfish-cbc         2.77k       10.81k       42.28k      140.27k      343.05kdes-cbc              2.53k        9.73k       35.20k      124.84k      624.88k3des-cbc             2.50k        9.72k       35.61k      115.21k      253.42k

The library has not been optimized for speed, and those numbers could probably be improved.

You can browse the source, download the source or download the SWC binary

Check out the release notes for a bit more details.

Things that should make it in the next release:

  • better ASN-1 parsing
  • SSL 3.0 support
  • various bugfixes (Socket, BigInteger)

SVN Location

Categories: Actionscript 3

The AS3Commons project


Tags: , is dedicated to one principal goal: creating and maintaining reusable ActionScript 3.0 components. This is a place for collaboration and sharing, where developers from throughout the community can work together on projects to be shared.

AS3Commons developers will make an effort to ensure that their components have minimal dependencies on other libraries, so that these components can be deployed easily. In addition, AS3Commons components will keep their interfaces as stable as possible, so that users (including other AS3Commons projects) can implement these components without having to worry about changes in the future.

We welcome participation from all that are interested, at all skill levels. Coding, documentation and testing are all critical parts of the software development process. If you are interested in participating in any of these aspects, please join us!

AS3Commons Libraries

Collections Collection framework formerly know as Lite Collections Fx 1.0 download docs
Concurrency Pseudo-threading support 1.0-RC1 download
Lang Language utilites and extensions 0.2.1 download
Logging An abstraction over logging framework implementations. Being a pure actionscript library it can be used for any Flash/Flex/AIR project. Its use is recommended for use with other libraries/framework trying to be logging framework agnostic. 1.1.1 download docs API
Reflect A reflection API for ActionScript 3.0. Being a pure actionscript library it can be used for any Flash/Flex/AIR project. 1.3 download docs API


All libraries are also available in the Maven repository at

Categories: Actionscript 3


Tags: , ,

The new ActionScript 3.0 Client Library for Facebook Platform API, fully supported by Facebook and Adobe, makes it easy to build applications that combine the strengths of the Flash Platform and Facebook Platform.

The Adobe Flash Platform and Facebook Platform provide the ideal solution for building rich, social experiences on the web. Flash is available on more than 98% of Internet-connected PCs, so people can immediately access the applications, content, and video that enable social interactions. The Facebook Platform is used by millions of people everyday to connect and share with the people in their lives. Together, both platforms allow you to:

  • Share: Create rich interactions for users to share with friends.
  • Have fun: Make games social; let users compete against their friends.
  • Connect: Let users connect to your RIAs with Facebook Connect.
  • Solve problems: Build RIAs that harness the power of community.
  • Reach people: Reach millions of Facebook users through social distribution.

Getting Started

For tutorials, articles, and videos on using the new API, visit the Facebook page on the Adobe Developer Center. You can also see the docs for the most recent and stable build.

Project History

The API was originally developed by Jason Crist and authored under the direction of Terralever, an online marketing firm with strength in Flash-based media. Although Adobe has taken over day-to-day management of the project, Jason still maintains a consulting role. Under the direction of Adobe, the highly experienced team of Flash and Flex experts from have developed and architected the latest iteration of the API.

If you are looking for the deprecated code and samples, see the ‘tag/version2’ directory in the repository or search for files with the ‘Deprecated’ tag in the downloads section.

For questions and inquiries about this library, please contact Daniel Dura at Adobe Systems via email at Submit bug reports, patches, or feature requests via the issue tracker.

SVN Location

GA for Flash

Categories: Actionscript 3

An XPath implementation for ActionScript 3.0.


An XPath implementation for ActionScript 3.0.


XPath-AS3 can be used in any AS3 project, including:


Basic overview of how to use the XPath library

Executing XPath Statements

XPath queries are evaluated using the XPathQuery object.

// create the XPathQuery instance and parse the path
var myQuery:XPathQuery = new XPathQuery("path/to/evaluate");
// execute the statement on an XML object and get the result
var result:XMLList = myQuery.exec(myXML);

Using namespaces

To use namespaces, you need to register namespace prefixes with the corresponding URI. This prefix does not need to match the prefix used in the XML document, but must match the prefix that you use in your XPath statements.

var myQuery:XPathQuery = new XPathQuery("ns1:path/to/ns2:evaluate");
.context.namespaces["ns1"] = "";
.context.namespaces["ns2"] = "";

Short-hand Namespace handling

There are two more convenient ways of adding the namespaces, by either opening all the namespaces, or automatically declaring the same prefixes as the document.

By setting ‘useSourceNamespacePrefixes’ to true, any namespace declarations in you the XML document will be automatically declared for the XPath expression, using the same prefixes:

var myQuery:XPathQuery = new XPathQuery("ns1:path/to/ns2:evaluate");
.context.useSourceNamespacePrefixes = true;

The easiest (although perhaps least safe) way is with the openAllNamespaces property. Although, if there are several namespaces used in the document, there is a chance of name conflicts:

// no need for prefixes in this statement
var myQuery:XPathQuery = new XPathQuery("path/to/evaluate");
.context.openAllNamespaces = true;

The XPathContext object

The XPathContext object is how you can specify namespaces, variables and custom functions to use in your XPath statements. By creating an instance of XPathContext, you can pass it as an argument to the constructor all of your XPathQueries, so you do not have to set them all up individually.

// create the context instance
var context:XPathContext = new XPathContext();
// declare a namespace
.namespaces["ns1"] = "";
// define a custom variable
.variables["myCustomVar"] = true;
// Pass the context to the XPathQuery instance
var myQuery:XPathQuery = new XPathQuery("path/to/evaluate", context);

Alternatively, you can customise the default XPathContext, which will then apply to all XPathQueries, as long as you don’t also pass one as an argument.

// this namespace will be available to all XPathQuery objects
XPathQuery.defaultContext.namespaces["ns1"] = "";

Extending XPathContext

Sometimes it is more convenient to extend XPathContext and use instances of the subclass in your expressions. If you do this, it is important to override the copy() method, which is used internally in sub-expressions.

public class MyContext extends XPathContext {
public function MyContext(){
// add the custom functions to the functions table
['custom-function'] = customXPathFunction;

// custom XPath functions must receive a reference to the
// context as their first argument. You may have any number of other
// arguments of any type, and the return value can be any type.
private function customXPathFunction( context:MyContext, arg1, arg2.. ):String
// add code here

// extensions to MyContext must implement copy()
public override function copy():XPathContext
var clone:MyContext = new MyContext();
// use the utility method to make sure that all the built-in and
// internal properties are copied
( clone, this );
return clone;
var path:String = "path/to/evaluate[@att = custom-function(1,2)]";
var myQuery:XPathQuery = new XPathQuery(path, new MyContext()); 
SVN location
Categories: Actionscript 3 Tags: , ,

AS3 Webcam Motion Tracking

AS3 Motion Tracking and Detection

Detecting & Tracking Objects movement in Flash

Here’s how it works

  • After the camera object is set up, it is passed to a MotionTracker class I wrote, which extends the Point object. The MotionTracker class contains two BitmapData objects; one representing the current data from the webcam, the other is used to store the previous frame.
  • When the update method is called, the new frame is drawn on top of the previous using the difference filter.
  • The result then has a ColorMatrixFilter applied to it, increasing the contrast of the image and dropping the darker areas (with less movement) further into the background.
  • A blur filter is then applied in order to further reduce noise and to form blobs from areas where more movement is occurring.
  • The threshold method is then called in the resulting BitmapData, effectively causing all near black pixels to be ignored and all light pixels (where movement has been detected) to be set to a certain colour.

So that takes care of the motion detection, but what about the tracking?

  • First we call the getColorBoundsRect method on the BitmapData object, which gives us a Rectangle object representing the area occupied by pixels of the colour we used when applying the threshold filter.
  • If the rectangle has an area larger than a specified constant, then sufficient movement is occurring and it can be tracked (choosing to ignore small areas of movement helps to eradicate noise caused by background and other interferences).
  • We then find the centre point of this rectangle, and then move the x and y position of the MotionTracker instance to these coordinates, applying some gentle easing to give more continuity to the movement

AS3 Motion Tracking from Justin Windle on Vimeo.


Categories: Actionscript 3