Mimic import and package in FMS

If you follow the fms community you know lots of developers ask for a server-side scripting improvement. They even ask for server-side AS3.

But they are right, we need a better way to code but we don’t feel like sitting here waiting for Adobe to release a new version, we try to mimic what we need with what we currently have.

For example:

    function __package(str){
  1. var tmp = str.split(".");
  2. var ref = this;
  3. for(var i=0;i<tmp.length;i++){
  4. if(!ref[tmp[i]]) ref[tmp[i]] = new Object();
  5. ref = ref[tmp[i]];
  6. }
  7. return ref;
  8. }
  9. function __import(str){
  10. var path = str.split(".");
  11. load(path.join("/")+".asc");
  12. var cN = path.pop();
  13. this[cN] = __package(path.join("."))[cN];
  14. }

Examples:

Writing a class:

    // This should follow the folder structure of every normal class
  1. var p = __package("com.funciton.fms.events");
  2. p.EventDispatcher = function(){
  3. }
  4. var o = p.EventDispatcher.prototype;
  5. // etc

Importing that class:

    __import("com.funciton.fms.events.EventDispatcher");
  1. var tmp = new EventDispatcher(); // works!
  2. var tmp2 = new com.funciton.fms.events.EventDispatcher(); // also works!

if you wonder why we use the “__” characters at the beginning is because even import or package are not implemented server-side they are still reserved.

P.D1: We need a code highlighting tool for the blog!
P.D2: Yes, we have an EventDispatcher for fms and it’s based on what we have in AS3, i will share it soon