在as3中Embed(绑定)flash动画元素

ref:http://zszen.tbcheap.com/wordpress/life/?p=283 

你需要使用loader类的loadBytes方法将这个二进制流转换成显示类
如果你需要控制embed进来的元件, 那么你需要侦听loader.contentLoadInfo的Event.Complete事件
当完成装载后你既的内部embed元件就可以随心所欲的玩了
此时的loader.content即为MainTimeline类, 这时你直接写loader.content.txt严格的话会报错, 你可以使用弱引用 loader.content["txt"] 然后声明个临时变量, 在cs5里面还能给个代码功能提醒

附上我的demo附件作为例子看吧 (本地就不传了, 去论坛下吧)link

另外附上测试的embed各种格式的父类关系
jpg/gif/png:
Main_EMBED
mx.core::BitmapAsset
mx.core::FlexBitmap

swf文件:
Main_EMBED
mx.core::ByteArrayAsset

mp3声音类:
Main_EMBED
mx.core::SoundAsset

txt文本:
不支持
does not have a recognized extension, and a mimeType was not provided

xml文档:
不知道为什么这么报错
expecting semicolon before id

pdf文件同swf
zip压缩包同swf

另外font应该也是可以镶入的, 没测

官方文档里面提到了到底支持绑定什么类型的文件:http://livedocs.adobe.com/flex/3 … ontent=embed_4.html

收集到的各类文件镶入方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/** Embed SWF */
[Embed(source="$$(source).swf",
   mimeType="application/x-shockwave-flash",
   scaleGridTop="$$(scaleGridTop=1)",
   scaleGridBottom="$$(scaleGridBottom=1)",
   scaleGridLeft="$$(scaleGridLeft=1)",
   scaleGridRight="$$(scaleGridRight=1)",
   symbol="$$(symbol)")]
private var _$$(source)_$$(symbol)SWF:Class;

/** Embed Binary */
[Embed(source="$$(source)", mimeType="application/octet-stream")]
private var _$$(source)BIN:Class;

/** Embed Image */
[Embed(source="$$(source)",
   mimeType="$$(image/gif,image/jpeg,image/png)",
   scaleGridTop="$$(scaleGridTop=1)",
   scaleGridBottom="$$(scaleGridBottom=1)",
   scaleGridLeft="$$(scaleGridLeft=1)",
   scaleGridRight="$$(scaleGridRight=1)")]
private var _$$(source)IMG:Class;

/**
* Embed Font
* fontSharpness = -400 > 400
* fontThickness = -200 > 200
*/

[Embed(source="$$(source)", sourceList="$$(sourceList)",
   mimeType="$$(application/x-font,application/x-font-truetype)",
   fontName="$$(fontName)", systemFont="$$(systemFont)",
   fontStyle="$$(fontStyle=normal,italic,oblique)",
   fontWeight="$$(fontWeight=normal,bold,heavy)",
   advancedAntiAliasing="$$(advancedAntiAliasing=true,false)",
   flashType="$$(flashType=true,false)",
   fontGridFitType="$$(fontGridFitType=pixel,none,subpixel)",
   fontSharpness="$$(fontSharpness=0)",
   fontThickness="$$(fontThickness=0)",
   unicodeRange="$$(unicodeRange)")]
private var _$$(source)FNT:Class;

/** Embed MP3 */
[Embed(source="$$(source).mp3", mimeType="audio/mpeg")]
private var _$$(source)MP3:Class;

/** Embed SVG */
[Embed(source="$$(source)",
   mimeType="$$(image/svg,image/svg-xml)",
   scaleGridTop="$$(scaleGridTop=1)",
   scaleGridBottom="$$(scaleGridBottom=1)",
   scaleGridLeft="$$(scaleGridLeft=1)",
   scaleGridRight="$$(scaleGridRight=1)")]
private var _$$(source)SVG:Class;

/** ArrayElementType */
[ArrayElementType("$$(class=int)")]

/** Bindable */
[Bindable(event="$$(eventname=change)")]

/** DefaultProperty */
[DefaultProperty("$$(defaultProperty)")]

/** Deprecated */
[Deprecated(message="$$(message)", replacement="$$(replacement)", since="$$(since)")]
   
/** Effect */
[Effect(name="$$(name)",
   event="$$(event)",
   deprecatedMessage="$$(deprecatedMessage)",
   deprecatedReplacement="$$(deprecatedReplacement)",
   deprecatedSince="$$(deprecatedSince)")]

/** Event */
[Event(name=="$$(name)",
   type="$$(type=flash.events.Event)",
   deprecatedMessage="$$(deprecatedMessage)",
   deprecatedReplacement="$$(deprecatedReplacement)",
   deprecatedSince="$$(deprecatedSince)")]

/** Exclude */
[Exclude(name="$$(name)", kind="$$(kind=property,event,style)")]

/** ExcludeClass */
[ExcludeClass]

/** IconFile */
[IconFile("$$(iconFile)")]

/** Inspectable */
[Inspectable(category="$$(category=Other,Common,Effects,Events,Layout Constraints,Size,Styles)",
   defaultValue="$$(defaultValue)",
   enumeration="$$(enumeration)",
   environment="$$(environment=none,Flash,MXML)",
   format="$$(format)",
   listOffset="$$(listOffset=0)",
   name="$$(name)",
   type="$$(type=String,Array,Boolean,Color,Font Name,List,Number,Object,String)",
   variable="$$(variable)",
   verbose="$$(verbose=1)")]

/** InstanceType */
[InstanceType("$$(type=mx.core.UIComponent)")]

/** NonCommittingChangeEvent */
[NonCommittingChangeEvent(name="$$(name=change)")]

/** NonCommittingChangeEvent */
[RemoteClass(alias="$(Package).$(FileName)")]

/** Style */
[Style(name="$$(name)",
   type="$$(type=Class)",
   arrayType="$$(arrayType)",
   format="$$(format=Number,Color,Length)",
   enumeration="$$(enumeration)",
   inherit="$$(inherit=yes,no)",
   states="$$(states)",
   deprecatedMessage="$$(deprecatedMessage)",
   deprecatedReplacement="$$(deprecatedReplacement)",
   deprecatedSince="$$(deprecatedSince)")]

/** Transient */
[Transient]

/** --------------- UNDOCUMENTED --------------- */
/** SWF */
[SWF width="$$(width=800)",
   height="$$(height=600)",
   widthPercent="$$(widthPercent=100)",
   heightPercent="$$(heightPercent=100)",
   scriptRecursionLimit="$$(scriptRecursionLimit=225)",
   scriptTimeLimit="$$(scriptTimeLimit=15)",
   frameRate="$$(frameRate=30)",
   backgroundColor="$$(backgroundColor=0xFFFFFF)",
   pageTitle="$$(pageTitle)"]

/** Frame - maybe missing arguments */
[Frame(factoryClass="$$(factoryClass=mx.managers.SystemManager)")]

/** MaxChildren */
[MaxChildren($$(MaxChildren=0))]

/** Mixin */
[Mixin]
public static function init(root:DisplayObject):void

/** PercentProxy */
[PercentProxy("$$(PercentProxy)")]

posted on 2010-12-07 18:34  Tobin  阅读(1133)  评论(0编辑  收藏  举报

导航