- Home
- Tutorials
- Flash
- Intermediate
- ASSetPropFlags

Page 2 of 3
However, if we were to iterate over all the children in the _global object without first un-hiding the properties from the for..in loop construct:
for (i in _global) {
trace(i);
}
Nothing is outputted.
All of the predefined objects have their methods and properties hidden from the for..in loop construct, even the undocumented hidden objects. So if for example we wanted to find out what is contained inside of the NetConnection object we could use:
//un-hide all the children in the NetConnection
//objects prototype object
ASSetPropFlags(NetConnection.prototype, null, 6, true);
//iterate over all the children of the
//NetConnection objects prototype object
for (i in NetConnection.prototype) {
trace(i);
}
An interesting find, the output is:
addheader
call
close
connect
__proto__
constructor
So, their is a set process you can follow to achieve the desired results, first choose the object you want to act upon 'obj', then choose the children of that object that you want to act upon and create an array of those names 'props', then choose the behaviour you want to achieve by looking up the correct argument value in the table further up in this article 'n' and then if you are wanting to turn off any of the protection behaviours; un-hide from for..in, un-protect from deletion, un-protect from over-write you need to pass the fourth argument as the boolean value 'true' otherwise just omit this argument(dont pass it).
Lets create an object containing some properties and methods which we cant test the different behaviours of this function on:
//create a new object
myproperties = {};
//place a few properties inside
myproperties.firstname = "Guy";
myproperties.surname = "Watson";
myproperties.icq = 71063418;
Now lets try out the different behaviours on this object.
First lets see what happens when we iterate over all the children in this object before using the ASSetPropFlags function, we will make this code a function so we can re-use it later:
//define the function that iterates
//over all the children of the myproperties object
function doIterate() {
for (i in myproperties) {
trace(i);
}
}
//call the function
doIterate();
Hide some children from the for..in loop construct:
ASSetPropFlags(myproperties,["firstname","surname"],6,1);
And then run the iteration function again:
doIterate();
The output window shows:
icq
Hide all children from the for..in loop construct:
ASSetPropFlags(myproperties,null,6,1);
And then run the iteration function again:
doIterate();
The output window shows nothing.
Un-hide a property to the mercy of the for..in loop construct:
ASSetPropFlags(myproperties,["icq"],0,1);
And then run the iteration function again:
doIterate();
The output window shows:
icq
Un-hide all children to the mercy of the for..in loop construct:
ASSetPropFlags(myproperties,null,0,1);
And then run the iteration function again:
doIterate();
The output window shows:
icq
surname
firstname
Protect a property from deletion:
ASSetPropFlags(myproperties,["firstname"],2,1);
Try to delete the property:
delete myproperties.firstname;
Was the property deleted?
trace(myproperties.firstname);
The output window shows:
Guy
Un-Protect a property from deletion:
ASSetPropFlags(myproperties,["firstname"],0,1);
Try to delete the property:
delete myproperties.firstname;
Was the property deleted?
trace(myproperties.firstname);
The output window shows:
Continued overleaf...undefined
