views:

570

answers:

1

Does anyone know how AS3/Flash runtime handles trying to modify the prototype when working between sandboxes. In particular I create object O in sandbox A, then pass it to SandBox B. What is the effect if code in sandbox B tries to modify the prototype ? (do the objects in A of the same class see this ?). Can Sandbox B overwrite public fields and methods of the object created in sandbox A ( if the object is passed in as a param)? Is it possible to create an unmodifiable class (ie. the equivalent of say final in java) that can act as a ready only proxy to pass between loaded swf's and the main swf ? I know the event class can use clone() to sort of do this, and then pass the events between the 2 swf's. Is using a final class in AS3 the right way to create read only proxies that can't be modified at all ?

+2  A: 

you can always use the flash.utils.Proxy class, if you want a read only proxy to some object ...

ActionScript3 is not prototype based as 1 and 2 were (you would need to compile to ecma object mode, which comes at huge speed decrease) ...

it now has 2 inheritance mechanisms ... one is class based, and the other is prototype based and works only for dynamic properties of dynamic classes ... no sealed (i.e. not dynamic) class and no sealed property or sealed method of a dynamic class can be modified at runtime ... by modifying a property, i mean modifying its type, or adding a setter at runtime, or overwriting it ... if the property is writable, you can of course assign something to it ...

final only means, it cannot be subclassed ...

as far as i know, as soon as you pass an object O from sandbox A to B, code in B can access O very much the same way as code in A does ...

i don't know, if that answers you question ... maybe you could explain, what exactly you're up to ... :)

back2dos
thanks for the feedback. AS3 has 4 class visibility modifiers : dynamic, final , internal (default) and public. The as3 doc says if you specify dynamic, only then can a function add new properties and functions. Am i correct then in assuming this is the same as (new Object()).myprop = xyz ?
nso1
your assumption is correct ...to correct you, however, there are 3 visibility modifiers: public, internal and private (i.e. only visible to the main declaration in that file) ...dynamic specifies, whether properties may be added at runtime, and final, that you may not subclass the class ...just to illustrate my point:you could declare a public final dynamic class Foo ...but you cannnot declare a public internal class Foo ...for further explanation, you should may make a new question, since 600 characters is quite restrictive :)greetz
back2dos