Sep 1, 2010

Cross version compiling in AS3

Ever wanted to make a flash application behave differently depending on the plugin version of the user? That type of behaviour requires some planning beforehand and is totally doable.


Method availability could be done like this.

package
{
 public class PluginCapable
 {
  public static function methodAvailable(object:*, methodName:String):Boolean
  {
   try { object[methodName]; return true; }
   catch (error:Error) { }
   
   return false;
  }
 }
}

Say you wanted to check if the user could save locally...

var file:FileReference = new FileReference();
if (PluginCapable.methodAvailable(file, "save")) file["save"](data, "file.txt");
or simply hide the save button or something.

No comments: