AIR app – user idle detection

Wednesday, March 14th, 2012

Found out that it is super easy to deal with timeouts…i.e. when you create kiosk applications, you generally want the activity to timeout and go to some sort of attract screen or activity reset when no one has touched the screen, move the mouse or press the keyboard.

There’s the NativeApplication class for AIR to the rescue:

/* this is in seconds */
NativeApplication.nativeApplication.idleThreshold = 60;
NativeApplication.nativeApplication.addEventListener(Event.USER_IDLE, handleUserIdle);
NativeApplication.nativeApplication.addEventListener(Event.USER_PRESENT, handleUserPresent);

private function handleUserIdle (e:Event) : void
  //reset activity
  //show attract screen

private function handleUserPresent (e:Event) : void
  trace("There's a user!");
  //hide attract screen

AS3 – messaging between objects, a decoupled approach

Sunday, February 12th, 2012

I’m working on an interactive installation. I’m building a couple of AIR apps. A really useful object that I’ve worked with in the past is a Broadcaster. Think of it as the telephone operator of old…you know the kind at a switchboard that actually has to connect a wire between the two callers. Well, the Broadcaster is great for keeping objects decoupled from each other. Typically if you want to send message between objects, each object has to somehow know the existence of the other object. You do this by keeping a reference to it.

//This is inside the sender class
// save a reference to the receiver
// so we can tell it to do something later
var receiver;
receiver = {the_receiver_object};

With the Broadcaster class, you just tell the Broadcaster that you’re interested in a certain message. Any object in your application can fire that message. Once that is fired, you get an event and it’s up to your class to handle it.

// in the receiver class
// when we receive the "RESET" message,
// run the reset_activity() function.
Broadcaster.subscribe( "RESET", this.reset_activity );

function reset_activity ( e:RichEvent ) {
//do something

// in the sender class
// fire off the "RESET" message
// and also pass along some parameters "RESET" , {transition:"fade_out"} );


Notice that neither class has any knowledge of the other class. They are really just ‘connected’ by the message that they are firing and listening to.

The beauty of this is that any class can fire a message and any class can listen(subscribe) to that message. The Broadcaster does the routing between sender and receiver just like the old telephone switchboard days!

Here’s the awesome minair library that has the Broadcaster class. If you just want to use this messaging architecture you’ll need to grab the Broadcaster, RichEvent, and the Log classes. Good luck!

MVC and Actionscript

Friday, March 13th, 2009

I have to admit that I’ve tried to use the MVC pattern for coding projects in the past and have never committed fully to using it for all UI objects in the project. Sometimes MVC just seems like too much work for a simple button, for example. Maybe, I just don’t understand how to apply the pattern, but I’m pretty sure I understand the concept. To me, the MVC pattern still has points of tight coupling. For example, your View subscribes to Model events. The Controller holds onto references to the Model and the View.

I’ve just found PureMVC and am trying to understand their implementation. It seems like their architecture is based on really loose coupling. Objects subscribe to messages (not tied to an object at all), and other objects broadcast messages. Subscribers and Publishers don’t know about each other. It sounds like a good idea to me. I’ve seen examples out there of eventmanager objects (subscribers and publishers interact with the eventmanager via the subscribing and publishing of messages) and have used them in projects before and PureMVC sounds like it’s built around this flexible way for objects to communicate with each other. One down side could be that there may be too many message flying around the system. I’m still trying to get my head wrapped around this so let’s see how well this works. I’m following this tutorial.

Flash and Internet Explorer ActiveX focus issue

Saturday, February 24th, 2007

I’ve been doing most of my development on the Mac these days so I haven’t touched Internet Explorer. I’ve also been avoiding general HTML and been using Flash because dealing with browser incompatibilities makes my head spin. So who would have thought that there might be a slight user interface issue regarding Flash and IE?

If you publish your .swf and .html, Flash puts in the necessary OBJECT and EMBED tags in there for you. This works in all browsers EXCEPT for IE on Windows. OK, it doesn’t necessarily render your Flash movie unusable, but it does require that the user click on the Flash movie BEFORE you can actually interact with it. Here’s the Adobe article that explains it and contains a Javascript fix. It’s an annoyance for the user or the the user might think that the Flash movie is broken. The fix requires two Javascript libraries and a call to one of the the functions to embed your movie so that you don’t get see that weird behavior in IE for Windows.

Now, if you are passing GET style parameters to your flash movie inside your EMBED and OBJECT tags, you’ll have to modify one of the functions to accommodate these parameters.Add this in AC_RunActiveContent.js:

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
switch (currArg){
case "GET_parameters":
ext = ext + "?" + args[i+1];



So, if you want to pass two parameters to your Flash movie, greeting and foo, now your javascript call will look like this instead:

'movie','test_flash_movie' ); //end AC code

Audacity and disappearing Flash 8 Pro sound

Thursday, December 28th, 2006

I was working in Flash 8 Professional on my new MacBook Pro (Core Duo) running 10.4.8 when all of a sudden no sounds play in my development environment.  I test in my browser and the sound works!  I try it again in my Flash 8 Pro, and no dice.  It had my frustrated for a couple of days until I found this article with a section entitled Disappearing Quicktime Sound in Audacity’s wiki.  I tried their solution of running Garage band an voila! all is normal again.  How wacky.  I hope others that are experiencing the problem find this blog entry so they won’t have to go through what I went throug.  Ugh!

Open source Flash Development

Friday, March 24th, 2006

I’ve been aware of MTASC for awhile now but haven’t tried it until today.
It all started out with a search for an Eclipse plug-in for Actionscript. I chanced upon this page which contains a great tutorial for acquiring and testing out all the tools you’ll need to start compiling .swf’s.
These are the pieces you’ll need:

  • Eclipse – open source IDE
  • ASDT – eclipse plug-in for Actionscript development
  • MTASC – open source Actionscript compiler
  • Flashout – eclipse plug-in that gives you a function similar to “Test Movie” in Flash

MTASC comes with all the classes for MX and 8 (the site mentions its successor, haXE, which will support Flash Players 6-7-8 and 8.5 as well as Javascript and Server-Side scripting.)

I had a little bit of trouble working with Flashout on my Mac running OS X Tiger. When I was trying to configure Flashout in the Eclipse preferences I kept getting an error message saying that it couldn’t find the FlashoutMTASCPreferences class. It turns out that Flashout requires Java 1.5 which doesn’t come with Tiger. This page gives you the fix. Essentially you have to download Java 1.5 from Apple’s site and then you need to point the CurrentJDK folder to the 1.5 folder.