« We are back! | Home | FMS *components* »
July 25, 2007
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){
var tmp = str.split(".");
var ref = this;
for(var i=0;i<tmp.length;i++){
if(!ref[tmp[i]]) ref[tmp[i]] = new Object();
ref = ref[tmp[i]];
}
return ref;
}
function __import(str){
var path = str.split(".");
load(path.join("/")+".asc");
var cN = path.pop();
this[cN] = __package(path.join("."))[cN];
}
Examples:
Writing a class:
// This should follow the folder structure of every normal class
var p = __package("com.funciton.fms.events");
p.EventDispatcher = function(){
}
var o = p.EventDispatcher.prototype;
// etc
Importing that class:
__import("com.funciton.fms.events.EventDispatcher");
var tmp = new EventDispatcher(); // works!
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