Using Flash ActionScript 3 in GrandVJ 1.2b1

19
Oct/09
6

Author:

About: Software Architect at ArKaos
Web: http://nostromo.noisepages.com/


As you might have seen from the list of new features in GrandVJ 1.2, we now have support for Flash ActionScript 3.
(Update: MediaMaster also supports AS3 as of version 1.2, so this is valid for MediaMaster also).

The issue that prevented previous version to support ActionScript 3 was that Adobe has upgraded their security mechanism preventing global variable declarations to be exposed to external parties (as explained in this great tutorial by Ben Guerrette).

However, in ActionScript 3, you can declare functions to act as external interface, allowing to communicate with the Flash movie through a specified channel.

So in order to retrieve/set variables in ActionScript 3, you need to create two functions “arkSetVariable” & “arkGetVariable” and declare them as external interface:

import flash.external.ExternalInterface;

ExternalInterface.addCallback("arkSetVariable",arkSetVariable);
ExternalInterface.addCallback("arkGetVariable",arkGetVariable);

function arkSetVariable(varname:String, varval:String):void {
...
}

function arkGetVariable(varname:String):String {
}

The way you decide to implement these function is pretty much up to you. Since ActionScript 3 supports named arrays, an easy implementation would be:

function arkSetVariable(varname:String, varval:String):void {
arkVariable[varname]=varval ;
}

function arkGetVariable(varname:String):String {
return arkVariable[varname] ;
}

As these function use an array arkVariable using the variable name as index.

One last thing we need to do is to make sure the variable we need are initialised at startup. Failing to do this, they won’t exist in the array and GrandVJ will think they don’t exist and won’t update them.

Something like:

arkSetVariable("text","undefined") ;

Will call our function to set the “text” variable to “undefined” so that it is seen and updated by GrandVJ.

Here’s a little zip file containing a Flash file and it’s source code so you have a place to start with.

Let us know how it works for you!



If you enjoyed this article please consider subscribing to our rss feed!

Comment policy:
We love to hear from you. So feel free to comment, but keep in mind the basics of blog etiquette — no spam, no profanity, no slander, etc. All comments are moderated.

Please do not ask for technical support here: for a better service use our Support Center instead.

Comments (5) Trackbacks (1)
  1. ecin
    18:30 on October 19th, 2009

    Excellent! I’ll have to upload some AS3 versions of the source files I included for both tutorials.

  2. Matt Beghin
    19:18 on October 19th, 2009

    Wow ! You rock nostromo ! I was just wondering how to deal with that ! Thanks ;-)

  3. Brady Georgen
    04:12 on June 24th, 2010

    It appears that the link to the example zip files is dead. I’m really interested in using AS3 with Arkaos – as well as potentially PixelBender. Please let me know where I can see an example of the ExternalInterface implementation or a list of the variables that Arkaos exposes to the AVM. I’ve heard rumors that Arkaos will expose OSC and MIDI mappings – I’d love to get that in action.

  4. Oliver
    19:48 on July 15th, 2010

    Can you pleaseprovide the AS3Template.zip file! The link is broken.

  5. polanri
    15:50 on July 16th, 2010

    The link has been fixed, sorry for the delay..

Leave a comment

Copyright © 2012 ArKaos s.a. · Blog powered by Wordpress · Original theme Lightword by Andrei Luca