Category: ActionScript

PS3 and WII Flash capabilities dump

I ran a simple Flash capabilities dump script on both the Nintendo WII and the PS3. I then did a diff of the two outputs against each other and against a PC.
Below are the results:

WII/PS3 to PC Differences

  • PrintJob methods missing on the WII and PS3
  • WII to PS3 Differences

  • PS3 has names property for Camera and Microphone, WII does not
  • WII/PS3 Version Strings

    PS3 7,0,70,0
    WII 7,0,70,0

    WII/PS3 Flash Capabilities Output
    Continue reading

    Making SWFs Aware of Browser Sessions

    In my previous post about the Nascar slideshow, I mentioned how the module had variant behavior based on whether you had seen it or not during the current browser session. Though I briefly described the process to make this happen, I’ve decided to share example code of how this is done.

    What is a Browser Session?
    First off, when I speak of a browser session it is important to know exactly what I mean. Loosely defined, a browser session is the time duration from the point at which a session is started (while the browser is open) until all instances of that browser are closed. A session typically can be started by setting the session on entrance to a site, at login to a site, or at some other predetermined time.

    Does a SWF know about a Browser Session?
    A SWF has no internal way of knowing whether it was being visited another time by navigating in the same browser (page forward, page back, page refresh, etc), or whether it is the initial visit by a fresh browser instance. This lack of knowing presents an issue of being able to act on a temporary browser session. Essentially, the SWF doesn’t know when or how it was opened. For example, setting a Shared Object and reading it, you don’t have a way to clear it when a browser closes (without help) or know whether it was set before you restarted your computer. Thus it knows nothing of its opening relationship, only that it was opened. Instead, the information has to be given to the SWF by the browser, since the browser is aware of it.

    Making the SWF aware of the Browser Session
    In order to do make the SWF aware of the session, you can create a browser based session cookie (a temporary cookie that is removed when the browser is closed). You can then pass the existance of this cookie into the SWF as a FlashVar with a Boolean value. If it exists you know that you are in a current session, if not the SWF is being opened for the first time in this particular browser instance. The timing at which you do this is important, as you want to write out the SWF first, then create the session cookie so it is available for subsequent embeds .

    Using SWFObject, adding the session information to a swf is pretty easy to do:

    var so = new SWFObject("TestBrowserSession.swf", "session" , 50, 50, 6, "#FFFFFF");
    // session flag to swf
    so.addVariable("FLASHVARS_hasSession", (document.cookie.indexOf("session=exists")!=-1) ? "true" : "false");
    // set session
    document.cookie = "session=exists;";

    A working example can be seen here.

    MouseWheelManager Class

    Flash allows you to capture the events from a mouse wheel. The event fires with two params (delta:Number, scrollTarget:MovieClip). In most cases, you only want one thing to respond to this event. For example, if you have two listboxes with scrollbars, you only want the one that your mouse is over to respond to the event. You could accomplish this by having each element listen for the wheel event and do it’s own check to determine whether it should handle it or not. However, if you did this everytime the event fired, all the handler checks would have to run. In the case of having 50 elements listening, that would be 50 if checks, which is inefficient.

    If you dig into the Flash component classes, you will find they implement the check rather intelligently. In mx.core.ScrollView, a single listener is implemented. The handler evaluates the second param (scrollTarget) to determine which component should handle the event. It does this by starting at the MovieClip target passed in and working up the parent chain until it finds a MovieClip that is a ScrollView instance. Once it finds that instance, it makes the instance dispatch a scroll event.

    I created a MouseWheelManager class that has the same intelligence as the ScrollView, but is a lot simpler to use . To utilize it with an Class or Object, instead of making that class subclass ScrollView (doesn’t rely on additional classes), the class just has to have a onMouseWheel handler and register itself and associated MovieClip with the manager.

    * Dreamsocket
    *  @author : Kenny Bunch
    *  @example:
    *           import com.dreamsocket.managers.MouseWheelManager;
    *            var o:Object = {};
    *            o.onMouseWheel = function(p_delta:Number, p_startingTarget:MovieClip):Void
    *           {
    *                  trace("works");
    *           }
    *            MouseWheelManager.getInstance().register(foo_mc, o);
    class com.dreamsocket.managers.MouseWheelManager
            private static var  k_instance:MouseWheelManager;
            private var m_targets: Object;
            private function  MouseWheelManager()
                   this.m_targets = {};
            public static function getInstance():MouseWheelManager
                     if(MouseWheelManager.k_instance == null)
                            MouseWheelManager.k_instance = new MouseWheelManager();
                    return MouseWheelManager.k_instance;
            public function register(p_tgt:MovieClip, p_instance:Object)Void<
                    this.m_targets[p_tgt] = p_instance;
            public function unregister(p_tgt:MovieClip):Void
                    delete (this.m_targets[p_tgt]);
            private function onMouseWheel(p_delta:Number, p_startingTarget:MovieClip) : Void
                   var testTarget:MovieClip = p_startingTarget;
                    var target:MovieClip;
                    while(testTarget != null)
                           if (this.m_targets[testTarget] != null)
                            {       // target exists in list and is bottom of tree set as target and stop climbing parents
                                  target = testTarget;
                            //  child mc is not a target climb to parent and test
                         testTarget = testTarget._parent;
                    if (target != null)
                    {       // target found dispatch event
                          this.m_targets[testTarget].onMouseWheel(p_delta, p_startingTarget);

    AS3: Visualizing Video

    In an attempt to start using AS3 and Flexbuilder, I created a simple module (based in part on Brendan Dawes “Cinema Redux” processing experiment), that visualizes a movie by taking snapshots of frames on a supplied sample rate. It uses those snapshots to create a visual mosaic image, which allows you to see the use of light, color, and transition throughout the movie.
    Continue reading

    BrowserHistory AS1 Class and Files

    I originally posted my AS1 BrowserHistory class and associated files in 2002 and it was distributed on various sites. In 2005, with my own site, I decided to finally give it a permanent home

    Normally, pressing a browser’s forward or backward navigation buttons on a Flash page will take you out of the movie. The BrowserHistory class allows developers to create a history list that can trigger actions based on the use of these buttons.

    I have noticed a number of solutions out there that attempt to resolve the back button problem, most noteably Robert Penner’s work ( and more recently Mike Chamber’s Pet Store back button. Robert introduced using MX’s LocalConnection object to get around all the browser issues, and I really like the new solutions that implemented this approach, however all of them seem to be missing something. Robert’s required the creation of a new swf and html page for every History object. Mike’s limited you to passing strings through the browser’s url and doing your own data conversions. The javascript approach also didn’t work in the newer Netscape and Mozilla browsers, because appending variables to a url is not treated as a new history object in the browser.

    What I really wanted from a History object in Flash was something that:
    1) would work on all platforms and browsers with the 6 player
    2) would be as simple to use as adding History elements through script and defining a function to handle a history event
    3) would only require including extra files and not manipulating them
    4) would allow me to work with any predefined datatype

    In my attempt, I tried to accomplish these goals by moving the persistant storage of the History elements into a SharedObject instance and using 4 predefined swfs and their accompanying html files (total of 8 files) to create a way of checking status. Since there are only those 8 files used in tracking status, no matter how many history elements you add, a user will only request a total of 8 additional files (this is nice if you think about server loads, the other methods request a file for every history element). Using this method of storage and status does not require the manipulation of extra files, instead all of the work is done “behind the scenes” by the BrowserHistory Class, the only requirements are that you include the proper files and know how to script a BrowserHistory instance.

    I hope that this can be of use to someone.
    ENJOY 🙂
    Kenny Bunch