do, after 2 days of messing around with it, I created a simple wrapper class
for it that does my bidding:
More about D.eval here: http://www.riaone.com/products/deval/
Source code for my class below for your use: (highlight, cut and paste)
package com.JMIM02.DynamicGetSet{
import r1.deval.D; //This library can be downloaded at:
//http://www.riaone.com/products/deval/
//What this class does:
//Allows you to dynamically get and set values of attributes in a class.
//Use in my "attribute spy" class to get and set values of selected class
//objects.
//Usage:
//This class is a key piece in the parameter editor UI I am writing for flash.
//When you click any object, you will see all of it's public variable and
//accessor values and be able to set them.
//Though many programmers frown upon using "eval()", the eval() command
//makes my attribute editor work with ANY class. Without eval(), I would
//have to modify any class with special get/set methods specifically
//designed for use by my parameter editor.
public class DynamicGetSet {
public var iObj:Object; //Must be public, else will NOT work.
public var rtnV:* ; //return value for D.eval command.
public function DynamicGetSet() {
// constructor code
}//Empty Constructor.
public function setVal(
inObj, //Object you are acessing.
propertyStr, //Property as string.
valueString //Value as string.
){
iObj = inObj;
var eStr:String = "iObj." + propertyStr + "=" + valueString;
D.eval(eStr,this);
}//[x]
public function getVal(
inObj, //Object you are acessing.
propertyStr //Property as string.
):*{
iObj = inObj;
D.eval("rtnV = iObj.publicVar",this);
return rtnV;
}//[x]
}//[class]
}//[package]
No comments:
Post a Comment