| ASSetPropFlags |
| This
function is used internally during the initializion stage for the
predefined actionscript objects. It is used to hide an objects children
from the for..in loop construct. The for..in loop construct iterates
over all children of an object, this means it exposes both methods and
properties of an object. It is also used to protect the predefined
actionscript objects children from being over-written by another action
with the same name and to protect the predefined actionscript objects
from being deleted. The usefulness of this function can also be
harnessed by the developer and that is when this function gets
interesting... ASSetPropFlags can be used to: Hide objects children from the for..in loop construct ASSetPropFlags(obj,props,n,allowFalse) The first argument 'obj' is the object that this function is to act upon. The Second argument 'props' is a list of child names contained inside of the object passed as the argument 'obj' in the form of a comma-delimited string or an array onto which this function will act upon. If you pass the value 'null' for this argument, this has the same effect as passing an array listing 'all' of the children contained inside of the object passed as the argument 'obj'. So for example:["start","stop","reset"] Will act upon the children named start, stop and reset as will:"start,stop,reset" The third argument 'n' is a number which represents three bitwise flags which are used to determine whether the list of child names should be hidden, un-hidden, protected from over-write, un-protected from over-write, protected from deletion and un-protected from deletion. Refer to this table for the results achieved by the different possible values for this argument:![]() The fourth argument 'allowFalse' is a boolean value(true/false) which is used to specify whether the three different types of protection, protect from over-write, protect from deletion and hide from for..in loop constructs can be set to false. If this value is ommited(not passed) then the default value 'false' is used, meaning you cannot un-protect from over-write, you cannot un-protect from deletion and you cannot un-hide from the for..in loop construct. ASSetPropFlags was exposed in Flash 5, however the fourth argument 'allowFalse' was not required as it always defaulted to the value 'true'. When Flash MX was released, people tested to see if this function still existed, obviously it did exist and so the clever people amongst the beta testers, used this function to get a list of all the undocumented objects,methods,properties and functions that existed in Flash MX: //un-hide all children contained CustomActions for(i in _global){ //un-hide all the children in the NetConnection addheader //create a new object //define the function that iterates ASSetPropFlags(myproperties,["firstname","surname"],1,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,1,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 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:undefined Re-define the properties value so we can use it again in the further examples:myproperties.firstname="Guy"; Protect all properties from deletion:ASSetPropFlags(myproperties,null,2,1); Try to delete the properties:delete myproperties.firstname; trace(myproperties.firstname); Guy ASSetPropFlags(myproperties,null,0,1); Try to delete the properties: delete myproperties.firstname; trace(myproperties.firstname); undefined myproperties.firstname="Guy"; ASSetPropFlags(myproperties,["firstname"],4,1); Try to over-write the property:myproperties.firstname="Richard"; Was the property over-written?trace(myproperties.firstname); The output window shows:Guy Un-protect a property from being over-written:ASSetPropFlags(myproperties,["firstname"],0,1); Try to over-write the property:myproperties.firstname="Richard"; Was the property over-written?trace(myproperties.firstname); The output window shows:Richard Re-define the property so that we can use it in further examples:myproperties.firstname="Guy"; Protect all properties from being over-written:ASSetPropFlags(myproperties,null,4,1); Try to over-write all the properties:myproperties.firstname="Richard"; trace(myproperties.firstname); Guy ASSetPropFlags(myproperties,null,0,1); Dont forget that you can assign multiple behaviours at once, by choosing the appropriate argument value for 'n' from the table further up the page, so for example you can protect all the listed properties 'prop' from being over-written and from being deleted in the same function call, you could also do the same for only a selected list of properties by passing an array of the child names for the value 'prop', alternatively you could hide all the properties of an object and un-protect them from being deleted and over-written in the same function call. There are 7 different combinations of behaviours. Personally, i usually use this undocumented feature to loop through all of the predefined objects to see what i can find lurking in the depths of hidden land, but i also use it to hide properties from for..in loop constructs and therefore also the 'Control>List Variables' output window when testing my scripts. This function comes in very handy when creating your own classes and also when you are defining methods and properties in the _global namespace, using ASSetPropFlags when defining methods and properties in the _global namespace can stop your code from being over-written or deleted. |