hello!
i have made a tool for controlling objects/properties/methods at runtime. it works fine, but i wish to integrate tweenmax so i could easily control complex things like colorMatrixFilter as well.
it almost works and about half the time it tweens them, but sometimes it doesnt, and it overwrites filters in a funny unpredictable way etc. i was wondering if someone could help me. this is my code:
package {
import flash.display.MovieClip;
import com.gskinner.utils.StringUtils;
import com.greensock.*;
public class test extends MovieClip {
public var resets:Array = new Array();
public function control(variable:String, property:String, value:String, time:Number = 0, before:String = ""):void {
var m = getMC(this, variable);
if (before != "" && resets[before] == undefined) {
var pre:Object = new Object();
for (var i:String in m) {
pre[i] = m[i];
}
resets[before] = pre;
}
if (property.indexOf("Filter") != -1) {
var h:Object = new Object();
var n:Object = stringToObject(value);
h[property] = n;
h["overwrite"] = true;
TweenMax.to(m, time, h );
}else if (property in m) {
if (m[property] is Boolean) m[property] = Number(value);
else m[property] = value;
trace(property, ":", m[property]);
}
}
public function getMC(prev:Object, str:String):Object {
var m:Object;
if (StringUtils.contains(str, ".")) m = getMC(prev[stringUtils.beforeFirst(str, ".")], StringUtils.afterFirst(str, "."));
else m = prev[str];
return m;
}
public function stringToObject(tString:String):Object {
var object:Object = new Object();
var stripped:String = tString.substr(tString.indexOf('{') + 1);
stripped = stripped.substr(0, stripped.lastIndexOf('}'));
var propArray:Array = stripped.split(',');
for (var i:uint = 0; i < propArray.length; i++) {
var objectProp:Array = propArray[i].split(':');
var propName:String = StringUtils.trim(objectProp[0]);
var propValue = StringUtils.trim(objectProp[1]);
object[propName] = propValue;
}
return object;
}
public function reset(variable:String, id:String):void {
var m = this[variable];
for (var i:String in resets[id]) {
m[i] = resets[id][i];
}
resets[id] = undefined;
}
}
}
thanks!
PS if anybody finds this code useful feel free, + if anybody can optimize it in any way please let me know!
thanks again,
michael