Tutorial details:
Written by: Guy Watson , MX 101
Time: 40 minutes
Difficulty Level: Intermediate
Requirements: Flash MX
Topics Covered: How to control the visibility of Objects' children to the for..in loop using ASSetPropFlags.
Assumed knowledge: Variables, Pathing, Scripted Loops, Objects.

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
Un-hide objects children to the mercy of the for..in loop construct
Protect objects children from being over-written
Un-Protect objects children from being over-written
Protect objects children from being deleted
Un-Protect objects children from being deleted

Unfortuneatley because this function has been exposed, the protection this function provides for objects children being over-written and deleted has been rendered useless, because of course, you can also un-protect them, the same goes for hiding actions from the for..in loop construct, you can of course also unhide them.

That aside, if Macromedia can use it to do the job then so can we.

The ASSetPropFlags function accepts four arguments:

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:



Editor's note:

According to this resource, the above table has since been proven to be incorrect. The same source sites the below table as the correct version:



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
//inside of the _global object
//refer to the table above to
//see the result of the third argument
//as the value '6'
ASSetPropFlags(_global, null, 6, true);
//iterate over all the children of
//the _global object
for (i in _global) {
 trace(i);
}

The above code outputs:

CustomActions
MMSave
Cookie
System
Accessibility
Video
Stage
TextFormat
TextField
Button
Key
Mouse
Selection
XML
XMLNode
Sound
Math
Array
String
Date
Boolean
Number
o
clearInterval
setinterval
isFinite
isNaN
updateAfterEvent
trace
parseFloat
parseInt
unescape
escape
ASSetNative
ASSetPropFlags
LocalConnection
SharedObject
Microphone
Camera
NetStream
NetConnection
Color
AsBroadcaster
XMLSocket
LoadVars
MovieClip
Infinity
NaN
Function
Object
ASconstructor
ASnative

Continued overleaf...