small coding-related outlet

coding-related things.

November 16, 2011 at 12:30am

91 notes

Connect to a remote Flash Media Server Shared Object from a client Flash.

Hardly mentioned anywhere, but, suppose you have a Shared Object on a running application in Flash Media Server (let’s call it: theApp), and you want to access it from the client:

THIS IS NOT ENOUGH:


var nc:NetConnection = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, function(e:NetStatusEvent) {
   if (e.info.code == "NetConnection.Connect.Success") {
       getSO:SharedObject = SharedObject.getRemote ("SOName", nc.uri, true);
   }
}
nc.connect ("rtmp://yourserver/theApp");

It won’t get an updated version of the SOName SharedObject, apparently. You have to call the “connect” method on the SO, and then wait for the SyncEvent.SYNC event:

var nc:NetConnection = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, function(e:NetStatusEvent) {
   if (e.info.code == "NetConnection.Connect.Success" {
       getSO:SharedObject = SharedObject.getRemote ("SOName", nc.uri, true);
       getSO.addEventListener (SyncEvent.SYNC, soSync);
       getSO.connect (nc);
   }
}
nc.connect ("rtmp://yourserver/theApp");

function soSync(e:SyncEvent) {
	trace ("SYNC!");
	trace (e.currentTarget.data.yourproperty);
        //Use the properties of the SO
}

And then the properties of the SO will be available in the data property.

October 17, 2011 at 7:25pm

0 notes

Cross-browser Flash Player version detection in Javascript

This post’s intention is to try to describe and achieve a light-weighted, 
cross-platform, cross-browser Javascript function that will detect the version of the Flash Player plugin installed on a browser, and return it, as a string.

The code is based on the Flash-Player version detection techniques used in the SWFObject source file.

The function return false if it is unable to find and detect the flash player’s version.

The function:


// Function to detect installed flash-player's version and return it as a 
// string in the format of 'MajorVersion.MinorVersion'

function getFlashPlayerVersion() {
    var nav = navigator;
    if (!nav) {return false;} 
    //If not navigator.plugins - assume IE
    if (nav.plugins.length == 0 || typeof nav.plugins == "undefined") {
        var ax = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
        if (!ax) {return false;}
        var flversion = ax.GetVariable("$Version");
        var retver = flversion.substring (flversion.indexOf(' ')+1,
                                          flversion.indexOf(',',flversion.indexOf(',')+1));
        //The Version variable in IE appears with a comma and not a dot - replace it:
        return retver.replace (',','.');
    } 
    //Has navigator.plugins - assume non-IE: 
    else { 
        if (!nav.plugins["Shockwave Flash"]) {return false;}
        var flashinfo = nav.plugins["Shockwave Flash"]; 
        if (flashinfo.version) {return flashinfo.version;}
        if (flashinfo.description) {
            //Parse just the version part from the description
            var fldesc = flashinfo.description;
            var flver = fldesc.substring (fldesc.indexOf('Flash')+6,
                                          fldesc.indexOf(' ',fldesc.indexOf('Flash')+7));
            return flver;
        } 
        else {return false;}
    }
}
    

The inner workings:

Detection for IE rely on the GetVariable(“$Version”) function of the ActiveXObject.
Detection for non-IE browsers rely on the navigator.plugins[“Shockwave Flash”] object.
Some browsers (e.g. Mozilla Firefox) has a version property for this object, other browsers has the version number inside the description property of the object.

Testing Table:

 Platform   Browser version   Flash version  Test result 
PC, WindowsFirefox 3.6Flash 8.0Works
Flash 9.0Works
Flash 10.0Works
Flash 11.0Works
Firefox 7Flash 11.0Works
IE 7Flash 10.3Works
IE 9Flash 11.0Works
Chrome 14.0Flash 11.0Works
Safari 5.1Flash 11.0Works
Opera 11.51Flash 11.0Works
MAC, OS X 10.5.8Safari 5.0.2Flash 10.0Works
Firefox 3.6Flash 10.0Works
Chrome: 15.0Flash 11.0Works