Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

define.as

Name: define() - defines variables in a scope
Author: senocular: www.senocular.com
Date: 1899-12-31T00:40:15.000
Documentation:
function DEFINE: defines variables to exist within a scope.
This can be helpful for use in with commands as with doesnt
allow defining of new variables in the with scope.  Newly
created variables would be put in the scope of the timeline.
Using define you can create those variables in the object scope
at the point in time you use the with statement.  Ironically,
the newly created variables in define are set to undefined.
There are two different formats of use:

define(obj, "list");
object.define("list");

Arguments:
- obj: (optional) if not used on an object directly, this parameter is used to specify
the object which recieves the variables in the list.
- list: A string of comma seperated variable names to be defined in the object.

Returns:
- returns a reference to the object in which define was applied.

Example:
 
myObj = new Object();
with (myObj.define("a,b,c")){
	a = 1;
	b = 2;
	c = 3;
}
for (p in mc) trace(p +": "+ mc[p]);

// output
a: 1
b: 2
c: 3

1
2
3
4
5
6
7
8
9
10
11
12
13
Object.prototype.define = function(obj, list){
	if (typeof obj == "string"){
		list = obj;
		obj = this;
	}
	list = list.split(",");
	var L = list.length
	while(L--) obj[list[L]] = undefined;
	return obj;
}
_global.define = Object.prototype.define
ASSetPropFlags(Object.prototype,"define",1);
ASSetPropFlags(_global,"define",1);