开发者

Block/prevent Loaded SWF from accessing Loader's Stage

开发者 https://www.devze.com 2023-04-08 08:58 出处:网络
I have two SWFs: a Loader SWF, and a Loaded SWF. I need to add the Loaded SWF to the display hierarchy, but I don\'t want to give it free access to the stage. It may, for instance, attempt to change t

I have two SWFs: a Loader SWF, and a Loaded SWF. I need to add the Loaded SWF to the display hierarchy, but I don't want to give it free access to the stage. It may, for instance, attempt to change the scaleMode, and I don't want that to happen.

What are some good methods for restricting loaded content's access to the stage? I may, for instance, want开发者_Go百科 to allow it to access the stageWidth and stageHeight, but not the scaleMode or align. Suggestions?

EDIT: Additional Constraints

I can't change anything about the Loaded SWF. Both SWFs are in the local-with-file-system sandbox. These SWFs are both Flash Player 10, ActionScript 3, made in Flash Professional. Not AIR, not Flex.

I'd love to be able to implement a proxy class or a getter to somehow intercept calls to the stage, but I don't believe there is any way to. I don't believe, for example, that you can subclass the Stage class and use that subclass in place of the normal Stage object referenced by the stage property in all MovieClips. The stage property is read-only, so it can't be cross-scripted by the Loader to point to something different.


By default, Flash will not allow a child SWF to access its parent's properties and methods, so you don't need to do anything.

Should you ever want to allow access you need to explicitly allow it using Security.allowDomain()

If you want the child SWF to access some properties but not others, you can use a sandbox bridge (complicated). Or you can have the child SWF "declare" what it wants to do. For example, add a property such as "requiredStageWidth" to the child. Then have the parent check for the existence of this property - if it's there, set the stage width, otherwise do nothing.


One solution could be to override the stage getter in your main swf and in that way prevent the loaded swf from accessing it. You would though have to return a valid object that simulates the stage to prevent errors in the loaded swf if it tries to access the stage.

public override function get stage():Stage{
        trace("trying to access stage")
        return new Object() as Stage
}
0

精彩评论

暂无评论...
验证码 换一张
取 消