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

 

senocular.com ActionScript Library

clearProperty.as

Name: clearProperty(); clears a property currently handled by getter/setter functions (set w/ addproperty)
Author: senocular: www.senocular.com
Date: 1899-12-31T00:33:42.300
Documentation:
Object CLEARPROPERTY: Clears a getter/setter property of an 
object (added with addProperty) from that object so that it's
free of that handling and back to a "normal" property.

Object.clearProperty("property", removeValue);

Arguments:
- property: string specifying the property of the object which is to have its getter/setter
functions removed.
- removeValue: (optional) a boolean value determining whether or not the current value of
the property is to be retained in the property after this method takes place.  If true,
the property is set to undefined (undefined value, NOT deleted).  Default: false.

Returns:
- the current value of the property whether or not removeValue is true or false.

Example:
obj = new Object();
getFunc = function(){
	return this.$prop * 10;
}
setFunc = function(value){
	this.$prop = value;
}
obj.addProperty("myProp", getFunc, setFunc);

obj.myProp = 5;
trace(obj.myProp); // 50

obj.clearProperty("myProp");
trace(obj.myProp); // 50
obj.myProp = 5;
trace(obj.myProp); // 5

1
2
3
4
5
6
Object.prototype.clearProperty = function(prop, removeValue){
	var orig = this[prop];
	delete this[prop];
	this[prop] = removeValue ? undefined : orig;
	return orig;	
}