[Laszlo-dev] SIngleton class that avoids a trampoline.

Philip Romanik promanik at laszlosystems.com
Tue Apr 15 18:23:48 PDT 2008


Hi Tucker,

I started with LzCursor as a model for a singleton class that doesn't 
use a trampoline to call the kernel-level implementation. LzCursor 
does not compile on swf9 so I worked on a solution that runs on each 
platform. Unfortunately, you lose compile-time error checking. I 
decided not to use this method for LzBrowser until we figure out if 
we need the added performance.




// Emulates a kernel-specific class
class LzTestKernel {
   static function staticmethod1 ()
   {
     if ($swf9) {
       trace("staticmethod1 called");
     } else {
       Debug.write("staticmethod1 called");
     }
   }

   static function staticmethod2 (arg1)
   {
     if ($swf9) {
       trace("staticmethod2 called: " + arg1);
     } else {
       Debug.write("staticmethod2 called:", arg1);
     }
   }

}


// Interface
class LzTestInterface {
   var func1:Function = function() {}
   var func2:Function = function() {}
}


// Implementation
class LzTestService extends LzTestInterface {
   static var LzTest:LzTestService;
   LzTestService.LzTest = new LzTestService();

   function LzTestService() {
     this.func1 = LzTestKernel.staticmethod1;
     this.func2 = LzTestKernel.staticmethod2;
   }
}

var LzTest = LzTestService.LzTest;



// Simple test
class Tester {
   function Tester () {
     LzTest.func1();
     LzTest.func2("arg1");
   }
}
var Testing = new Tester();



More information about the Laszlo-dev mailing list