//---------------------------------------------------------------------------- // (c) A T O M G A S, 2001 Luzifer Altenbetg, luzifer@atomgas.de // JS eval like function to do commands per string // Use this code for free as long as you keep this comments there // can eval assigments and functions calls version 0.2 // will need some work to be able to do this: doCommand("trace(escape(hallo))"); // // working calls : // doCommand("gotoAndStop(5);mc._x = 50;mc._yscale = 2500;mc._rotation = 15;mc._alpha = 15"); // doCommand("mc._xscale = 20") // doCommand("getURL(mailto:not@home.com?subject=hallo)") // doCommand("_root.aa = eval(_root.mc._x)"); // doCommand("_root.b = escape(hallo whats up?)"); //---------------------------------------------------------------------------- //needs the string.as from branden hall for good performance //http://chattyfig.figleaf.com/~bhall/code/string.as trace(">>>doCommand() - v 0.2"); String.protoType.trim = function(){ //do trim var st = getTimer(); var end = length(this); var start = 0; var white = new Object(); white["_"+ord(" ")] = 1; white["_"+ord("\n")] = 1; white["_"+ord("\r")] = 1; white["_"+ord("\t")] = 1; while(white["_"+ord(this.charAt(--end))]); while(white["_"+ord(this.charAt(start++))]); //trace("trim.time:"+(getTimer()-sT)+"ms"); return this.slice(start-1,end+1); } function doCommand(commandsStr){ var sT = getTimer(); var commands = commandsStr.split(";"); var agrs; for(var i=0;i < commands.length;i++){ //check what to do var startArgs = commands[i].indexOf("("); var functionName = (substring(commands[i],0,startArgs)).trim(); if(typeof(eval(functionName)) != "function"){ //assignment var parts = commands[i].split("="); var t = parts[0].lastIndexOf(".") var obj = eval((substring(parts[0],0,t)).trim()); var prop = (substring(parts[0],t+2)).trim(); if(parts[1].indexOf("(") == -1){ obj[prop] = parts[1]; }else{ doCommand(parts[1].trim()) obj[prop] = _root.retVal; } }else{ //function call var endArgs = commands[i].lastIndexOf(")"); var args = (substring(commands[i],startArgs+2,endArgs-startArgs-1)).split(","); _root.retVal = eval(functionName)(args[0],args[1],args[2],args[3],args[4],args[5]) } } trace("COMMAND TIME:: "+(getTimer()-sT)+"ms") } //-------------------------- _root.eval = function(input){ return eval(input) }