---
title: "swf加载swf的一些问题"
author: "xltank"
date: "2013-03-20T17:31:41Z"
tags: []
categories: ["Web前端"]
slug: "swf-swf"
draft: false
lastmod: "2013-03-20T17:31:41Z"
id: 1832834
url: "https://xltank.iteye.com/blog/1832834"
---

1，swfParent 加载 swfChild，如果有交互，需要在swfChild的构造函数中添加Security.allowDomain("mydomain.com") 或者干脆"\*"，不过有风险。

 

2，swfChild如果是flex 生成的，由于Application中没有构造函数，没办法一开始就设置允许的domain域，只好在swfParent中Loader.load("swfChild.swf", new LoaderContext(true, null, SecurityDomain.currentDomain)，把child放到parent的安全域中。有风险。

 

3，如果要使用child中的类，需要使用new LoaderContext(true, ApplicationDomain.currentDomain, SecurityDomain.currentDomain）。文档里讲的很清楚了，需要swfChild是用as3写的。

http://help.adobe.com/en\_US/FlashPlatform/reference/actionscript/3/flash/system/LoaderContext.html#applicationDomain

 

4，如果swfChild是as1 或as2 写的，那么加载的类型是AVM1Movie，基本无法控制，加载完成后添加到舞台多半就开始播放。如果是as3写的，则是MoiveClip，可以进行一些控制。

如果需要让swfChild在某个时候播放，可以先load完成然后不管，等到需要的时候再去load一次并添加到舞台，这样从缓存里load就快了。

 

5，有些swf添加到舞台后，会有背景色，可以在加载child的容器上使用mask，mask大小设置为loader.contentLoaderInfo.width / height。