User Guide

112 Server-Side ActionScript Language Reference
protectObject()
Availability
Flash Media Server 2.
Usage
protectObject(userObj)
Parameters
userObj An object to wrap in a C wrapper object.
Returns
An object.
Description
Method (global); protects user-defined or built-in objects behind a C wrapper object. The
methods of any object that has been passed to the
protectObject() function become system
calls because application code can never access or inspect the methods directly —only through
the wrapper. You can only use this function in the secure.asc file.
Flash Media Server 2 has two script execution modes: secure and normal. In secure mode,
only the secure.asc file (if it exists) is loaded and evaluated—no other application scripts are
loaded. Also, the global
getGlobal() and protectObject() functions are only available in
secure mode. These are very powerful because they provide complete access to the script
execution environment and let you create system objects. Once the secure.asc file is loaded,
the server switches to normal script execution mode until the application is unloaded.
After an object is protected, you must make sure it isnt directly accessible; dont reference it in
global variables or make it a member of an accessible object. The wrapper object returned by
the
protectObject() call dispatches all method invocations to the underlying user object
but blocks access to member data. As a result, you cant enumerate or modify members
directly. The wrapper object keeps an outstanding reference to the underlying user object,
which ensures that the object is valid. The wrapper follows normal reference rules and exists
while it is referred to.
For more information, see “Implementing secure system objects” in Developing Media
Applications.