hmm any less clutterfull way? I have to run this through a universal function and thats alot of code to add / clutter? I might end up jus tmake the input be an array and then have the path put it together.
so hmm I’m trying to figure out how the whole thing works cause I know it works and I got it to work with I need it to but I’d prefer to understand it so I can use it later :S
majorly the massive use of : between a variable and whatever ive never explored it in flash
Thats data typing… it just specifies data type of a variable (Number, String, MovieClip, BitmapData or any other class and interface) or a return type of a function (in this case its Object).
I have one little modifaction for that function…
function getReference(path:String, scope:Object):Object {
var broken:Array = path.split(".");
reference = scope[broken[0]];
for (var i = 1; i<broken.length; i++) {
reference = reference[broken*];
}
return reference;
}
Till now it allways looked for desired path in the scope, where function was. Now it doesnt realy matter where that function is declared and you can use it with specific scope… getReference(“someObj.someOtherOne”, _root) will look for someObj.someOtherOne in _root or getReference(“someObj.someOtherOne”, this) will return a reference to someObj.someOtherOne from where you are at the moment…
//edit one last thing to mention… Im sure you already know it but anyway…
Because that function returns the actual reference, you can store it and use it as normaly… for example:
someMovieClip = getReference(“someObj.someOtherOne.mc1”, this);
someMovieClip.play();
hmm one other unrelated topic while implementing it…
if I set this as a global function
_global.getTarget = function(path:String, scope:Object):Object {
var broken:Array = path.split(".");
target = scope[broken[0]];
for (var i = 1; i<broken.length; i++) {
target = target[broken*];
}
return target;
trace(target);
};
// this would be inside a different function
getTarget(path, this)._alpha = 50;
should work no? It's not even running the getTarget function cause it's not tracing :S