AS3嵌入swf元件库,如何访问指定的资源
来源:互联网 发布:公众号助手电脑版 mac 编辑:程序博客网 时间:2024/05/17 06:29
It’s been a long-time without a post. Part of the reason for that has been starting work at a new job (which involves a commute), and part has been that as part of my new job, I was actually encouraged to spend time playing World of Warcraft. To me, that’s like taking a crowbar to Pandora’s Box and having a peek inside. I learned quite a lot, but have also played just a few too many Warsong Gulches.
Back to work, and I was doing a little prototyping this evening, when I came across a familiar problem: InAS3
we can use
[Embed(source=
"asset.swf"
, symbol=
"symbol"
)]
private
var
symbolClass:Class;
var
symbol:MovieClip =
new
symbolClass();
to embed a symbol from an art SWF
in what is probably a code-builtSWF
. That’s great, but what if you want to embed an entire SWF
?
[Embed(source=
"asset.swf"
)]
private
var
assetClass:Class;
var
asset:MovieClip =
new
assetClass();
looks like it should do the trick, but you can’t access any of the information within the asset. That’s a real pain, the reason for which is pretty convoluted. I remembered working around this problem in the past, and happily managed to unearth a long-forgotten treasure in my codebase, which I thought I’d share (having rapidly refactored it to use as3-signals, naturally).
package
com.alecmce.util
{
import
org.osflash.signals.Signal;
import
mx.core.MovieClipAsset;
import
flash.display.Loader;
import
flash.display.LoaderInfo;
import
flash.display.MovieClip;
import
flash.events.Event;
public
class
UnpackEmbed
{
private
var
_ready:Signal;
private
var
_asset:MovieClipAsset;
private
var
_content:MovieClip;
public
function
UnpackEmbed(assetClass:Class)
{
_asset =
new
assetClass();
_ready =
new
Signal(UnpackEmbed);
var
loader:Loader = Loader(_asset.getChildAt(
0
));
var
info:LoaderInfo = loader.contentLoaderInfo;
info.addEventListener(Event.COMPLETE, onLoadComplete);
}
private
function
onLoadComplete(event:Event):
void
{
var
info:LoaderInfo = LoaderInfo(event.target);
info.removeEventListener(Event.COMPLETE, onLoadComplete);
_content = MovieClip(info.loader.content);
_ready.dispatch(
this
);
}
public
function
get
content():MovieClip
{
return
_content;
}
public
function
get
ready():Signal
{
return
_ready;
}
public
function
get
asset():MovieClipAsset
{
return
_asset;
}
}
}
When you embed a SWF in this way then instantiate it, Flash somehow conspires to create aMovieClipAsset
with a Loader
inside, which will be ‘loading’ the already-embedded content. The content is not available immediately (it may be sometimes, I have encountered cases where it was not), so you have to wait for anEvent.COMPLETE
to be fired before you can access it. This class exposes a signal that informs you when the content is ready. It could probably be more rigorous, such as including anisComplete
flag, but it serves my purposes, when used in the following manner:
[Embed(source=
"asset.swf"
)]
private
var
assetClass:Class;
asset =
new
UnpackEmbed(assetClass);
asset.ready.addOnce(onAssetReady);
private
function
onAssetReady(asset:UnpackEmbed):
void
{
// now we can access the asset.content!
}
- AS3嵌入swf元件库,如何访问指定的资源
- 确定swf嵌入资源的大小
- AS3.0嵌入swf后一个很奇怪的bug
- AS3 调用外部SWF中元件库中的元件
- AS3 加载外部SWF资源
- flex swf访问资源的路径问题
- AS3如何加载自身SWF
- AS3.0 解决方案)SWF 文件不能本地访问 只有仅限于文件系统的 SWF 文件
- 如何读取嵌入的资源
- 如何在AS3中引用swf中的元件、图片等资源以及布局信息
- 如何在AS3中引用swf中的元件、图片等资源以及布局信息
- swf 不能访问本地资源
- flex和嵌入的swf
- 使用嵌入swf的字体
- swf不能访问本地资源的一些解决办法
- 解决flashDevelop发布的swf访问本地资源报错
- Flash AS3.0加载外部资源(图片、MP3、SWF)的两种方式
- as3.0 [Embed]标签嵌入外部资源
- 并查集
- Linux下的ELF可执行文件的格式解析
- vim 插件:perl-support的修改和使用
- Android 仿 WP7 布局
- the different between C and C++
- AS3嵌入swf元件库,如何访问指定的资源
- 使用Ant来编译Flex应用
- Flex mxmlc编译命令选项
- Into Clause VS Let Clause
- 数组初始化 –memset or {0}
- mongodb过滤查询键值
- Eclipse常用快捷键和字体设置
- 如何在派生类中的隐藏基类的虚拟重载函数?
- 为什么要不断接触和学习新技术之我见