- 浏览: 1457315 次
- 性别:
- 来自: 苏州
文章分类
- 全部博客 (564)
- 算法 (7)
- 流金岁月 (1)
- Javascript (30)
- actionscript (108)
- as3.0 game (14)
- flex (84)
- fms2 (27)
- 正则表达式 (7)
- 开源组件代码(as3.0) (1)
- Pv3d (13)
- Cairngorm (4)
- vbs (54)
- VB程序设计 (26)
- 计算机应用与维护 (4)
- 职场实用穿衣技巧 (3)
- 历史风云 (15)
- 淡泊明志,宁静致远 (12)
- 情感 (26)
- 杂谈 (41)
- 越南风 (14)
- DirectX (9)
- Dev-cpp (11)
- 回望百年 (2)
- 建站经验 (2)
- Python (24)
- 网络赚钱 (4)
- php (2)
- html (1)
- ob0短址网 (1)
- ob0.cn (1)
- wordpress (1)
- pandas logistic (1)
- haxe (1)
- opencv (1)
- 微信小程序 (3)
- vue (3)
- Flutter (1)
最新评论
-
GGGGeek:
第一个函数滚动监听不起作用,onPageScroll可以
微信小程序--搜索框滚动到顶部时悬浮 -
naomibyron:
解决办法:工具 -> 编译选项 -> 编译器 ...
dev-c++中编译含WINSOCK的代码出现错误的解决方法 -
haichuan11:
这个…… 代码不全真的是让人很憋屈的感觉啊
actionScript 3.0 图片裁剪及旋转 -
chenyw101:
老兄能留个QQ号吗?具体的我有些东西想请教下你
用VB制作网站登陆器 -
yantao1943:
貌似有点问题,只派发一次事件啊
使用ActionScript 2.0或ActionScript 3.0处理音频文件的提示点(cue
Using mxmlc / Flex Builder, you can safely store any kind of binary data, text, or XML directly in your SWF if loading it at runtime is not possible or not desirable. Find out how below.
The Setup
My friend EJ was wondering if there was some way to compile XML directly into an application without putting it inline in code. Of course E4X allows you to type XML literals, but doing so with large blocks of XML can be problematic for a few reasons. You can’t edit this XML with an XML editor. The XML parsing inside Flex Builder can be faulty on occasion, causing ActionScript in the same file to be misinterpreted. Placing XML in your source files can make them unwieldy and large, and slow to parse.
An Idea, but Not the Right One
My initial idea was to use include. Even though #include is deprecated in AS3, the little-known include (no hash mark!) uses the same syntax and can include code in much the same way. The Flex framework uses this to include a common version number as a static field in many classes:
mx_internal static const VERSION:String = "3.0.0.0";
This line, found in the file Version.as is placed in the class definition of classes where include “Version.as” is found. However, you can’t just include arbitrary copy. The included code has to be one or more full lines. So my idea of using
protected var xml:XML = include "static.xml" ;
wasn’t going to work. It did work when I included the whole variable declaration in the XML file, but then the file wasn’t valid XML any more! Not even close. And not too much better than just typing inline.
The Solution
The solution here is much, much more powerful than the original hack might have been. The MXML and AS3 compiler, mxmlc, which is used by Flex Builder as well, has the ability to embed all kinds of video, graphics, other swfs, and fonts into a SWF. The [Embed] metadata tag / compiler directive works whether you are using Flex or simply AS3. [Embed] associates a bit of data with a class that is capable of representing it.
If you haven’t seen it used before, here’s a simple example where we embed an image in the SWF:
[Embed(source="assets/photo.jpg")] private const PhotoImage:Class;
And then you can use it:
var myPhoto:DisplayObject = DisplayObject(new PhotoImage());
So, I don’t know how Adobe is really implementing things under the hood, but I say the following with some certainty. The compiler, happening across your [Embed] directive, retrieves the source, and examines it to see what kind of file it is. Depending on the type of file you’ve asked the compiler to embed, the runtime class reference will produce a subclass of a particular kind of class which is appropriate for the data you’ve embedded. The compiler will take the source of that file, transcode it, preparing the data to be inlined in the SWF itself, and possibly preprocessing it, for example parsing SVG into vector shapes.
You should also know that depending on whether you’re using the Flex framework or not, I believe you will end up with different superclasses associated with your embedded assets. If you use Flex, you might see a FontAsset subclass where you would simply get a Font subclass were you only using ActionScript.
You can also embed SWFs and symbols from within SWFs, a technique I quite like. Simply use a symbol attribute in the compiler directive:
[Embed(source="MenuAssets.swf", symbol=”com.partlyhuman.assets.TopMenuItem”)]
protected const TopMenuItem:Class;
addChild(Sprite(new TopMenuItem()));
The transcoder should automatically know what to do with these kinds of assets:
- JPG/JPEG image files
- GIF image files
- PNG image files
- SVG/SVGZ vector image files (supports a subset of SVG 1.1)
- MP3 sound files
- TTF font files
- Installed system fonts
- SWF files and specific symbols inside SWFs
No, I Know What I’m Doing, Really
But get this! There are more things you can convince the transcoder to accept. By manually specifying the MIME type of the file, you can force the transcoder to interpret the data in some format. This is the solution to embedding any XML at compile time, and then some. In fact, you can embed any binary data you want in a SWF, as long as you know how to interpret it on the other side.
There may be additional interesting MIME types that are registered by the transcoder. These are, as far as I know, undocumented, so if you find an interesting one that’s not covered by the types above or these two introduced here, leave a comment.
Here, we see that we can import an XML file with MIME type text/xml, and it embedded as a subclass of XML.
[Embed(source="test.xml", mimeType=”text/xml”)]
protected const EmbeddedXML:Class;
var x:XML = XML(new EmbeddedXML());
trace(x.toXMLString()); //it should work!
To get this to work, you should keep the XML prolog in your XML file. With this technique, EJ didn’t have to load the XML asynchronously, it was embedded right in his SWF for instant access, binary compression, and easy deployment, and tight coupling with the build itself. He could also now use a normal, full-featured XML editor to mess with the XML source.
But it gets better! You can embed any binary data whatsoever in a SWF, as long as you know how to interpret it on the way out. To do this, use the directive to embed any file with MIME type application/octet-stream (an octet is just a fancy word for a byte, by the way, as a byte is eight bits, so a stream of octets is a fancy way of saying “a bunch of bytes”). The class comes out in ActionScript as a subclass of, can you guess? ByteArray!
Here, ActionScript genius Max knows how to parse a WAD file, which Doom and other ID games used for levels and sprites and all kinds of business. He puts it right in the SWF by embedding it as application/octet-stream and interpreting it as a ByteArray:
public class DoomTest extends Sprite { [Embed(source=”doom1-shareware.wad”, mimeType=”application/octet-stream”)] private const DoomWad:Class; public function DoomTest() { var wad:ByteArray = new DoomWad() as ByteArray; new DoomCore(this,wad); } }
(Full source here) And, passing it to his Doom playing engine, you start playing the shareware level of Doom that was embedded right in the SWF!
You can apply this technique to any binary data you’ve cleverly figured out how to parse. Of course, Flash knows very well how to parse all the file types described in the list above, but with some creative coding, that’s just the beginning!
14 Comments »
RSS feed for comments on this post. TrackBack URI
-
Holly Hell. That is quite intense. Someone do Hexen as well!
-
i just could not get the xml embedding to work as you said.
i kept getting Syntax Error: xmltagstartend unexpected if i included a doctype, or my xml would come out as null.
if anyone else is having this problem, i tried your second method and it worked:
[Embed(source=”info.xml”, mimeType=”application/octet-stream”)]
protected var EmbeddedXML:Class;var ba : ByteArray = (new EmbeddedXML()) as ByteArray;
var s : String = ba.readUTFBytes( ba.length );
xml = new XML( s );
xml.ignoreWhitespace = true;Comment by e.j. — October 9, 2007 #
-
oh and thanks for everything roger!!!! :)
Comment by e.j. — October 9, 2007 #
-
HI,
I have been trying to get the Embed with mimeType = “text/xml” to work with no luck,Keep getting a syntax errors. here is my code :package {
import flash.display.*;
public class Embed extends MovieClip {
[Embed(source=”/assets/employees.xml”, mimeType =”text/xml”)]
var theClass:Class;
public function Embed() {var xml:XML = XML(new theClass());
trace(xml.toXMLString());
}
}
}any idea ?
Comment by Tareq — October 9, 2007 #
-
Thanks, it worked.
Comment by Tareq — October 9, 2007 #
-
Hello,
I have the same problems mentioned in the other comments. I get also the error xmltagstartend unexpected. So how does it really work to embed XML?
Please help!Comment by Matthias — October 15, 2007 #
-
Hey Roger, are you sure the XML-example works for you? I tried it out in Flex Builder (2) and all I got was the toString() representation (”[object Model_EmbeddedXML]”)..
Comment by Ruben Swieringa — November 13, 2007 #
-
Hello Roger,
I’m having issues using your xml embed technique. I have a feeling it may be my prolog.
Would you be open to providing us with test.xml that you used in the example above so that we can test with an XML file that works?
Thanks!
Comment by Jun Heider — November 15, 2007 #
-
Hey Roger :)
That is cool example u have here.
Is there a chance it will work with *.flv ?
Actually I managed to embed it as byte array, but i could not figure how to translate it backwards.
The problem I’m dealing with is that my client wants to put the player I made on a CD and he wants the videos to be part of the swf.
Another way could be embedding the whole folder into swf.
Is there a chance someone ever had to do it ?
Thanks a lot.
Fell free to contact me on my skype, the address is : atlaseliComment by Eli — December 2, 2007 #
-
@Eli, I’m not sure you will have success playing back embedded FLVs, since the NetStream object seems to only want to load FLVs from remote locations… The one way I thought might work, though not exactly what you want, is to compress the videos as SWFs instead of FLVs, and then embed them and display with Loader.loadBytes().
Comment by Roger Braunstein — December 3, 2007 #
-
Hi Roger,
I am trying to embed an SWF created in Flash (CS3). After embedding it I want to access a parameter from it (a:String).
I am not able to do it.
[Embed(source=”3.swf”)]
private const SWFAsset:Class;and using it as
var swfMovie:MovieClip = new SWFAsset() as MovieClip;
now I want to access a variable “a” from the movie clip.
tried trace(”Val ” + swfMovie[’a'].toString());
Any ideas??
-
yeah I have to concurr this example does not seem to work or at least not in FB2.01 as an Actionscript project. Real shame as I am going nuts trying to embed XML too sensitive to load remotely. Do we have to set compiler properties or compile outside of flex builder using mxmlc to get this to work? Or will the XML parser only work within a Flex project?
-
looks like a bug in the transcoder perhaps or the relevant transcoder is unavailable for an Actionscript project this seems to work:
package
{
import flash.display.MovieClip;
import flash.utils.ByteArray;public class Test extends MovieClip
{
[Embed(source="data.xml", mimeType="application/octet-stream")]
private static const MyData:Class;public function Test():void{
var byteArray:ByteArray = new MyData() as ByteArray;
var xml:XML = new XML(byteArray.readUTFBytes(byteArray.length));
trace(xml.toXMLString());
}
}
} -
PS. Thanks Dan. http://www.dan-hunter.net
发表评论
-
haXe是什么?
2016-01-04 10:50 1093haXe是什么? haXe是一种编程语言,官方网站在 ... -
用EA类图生成AS3代码
2008-10-15 16:18 2735EA(Enterprise Architect)是支持多种流 ... -
变形实例-source
2008-10-15 12:46 1569涂抹原理 橡皮擦原理 import flash.geom.P ... -
actionScript 3.0 图片裁剪及旋转
2008-10-10 12:54 5973package com.wdxc { /** ... -
Flash(AS3)读取Excel文件
2008-10-09 13:29 5202var excelXml:XML; var loader=ne ... -
AS3 Loading的制作方法
2008-10-09 13:28 6089AS2的时候做LOADING有很多种方法,做起来也得心应手可是 ... -
让"Flash" 写文件(AS3)
2008-09-11 16:23 1811目前,出于安全考虑Flash不支持写文件的操作,在AS3的A ... -
AS3 中的 拖动 及 碰撞 检测
2008-09-11 16:11 2955没有press和release事件 hitTest()被分尸 ... -
As和js通信问题完全解析(解决addcallback失效的问题)
2008-09-11 16:10 3674as和js通信最早用的是fscommand,这个我就不说了,老 ... -
Flash CS3制作Fla形式的组件
2008-06-16 14:45 1407本文为大家介绍如何制作Flash CS3中的[*.fla]形 ... -
AS3图像处理之剪裁、动态选取
2008-06-15 23:25 2264和师傅写C#写的思维混乱,方法变量几乎第一反应就是大写,习惯都 ... -
从界面入手 划分类
2008-06-15 19:25 1303如何将一个项目细化成各个类呢? 1 从一个项目的界面入手,按照 ... -
AS3-DisplayEffect组件
2008-06-14 20:40 2097[AS3]DisplayEffect组件【组件版本】:0.5【 ... -
KTooltip 工具提示组件
2008-06-14 20:38 1048发布一个小工具KTooltip 。这是0.9beta版,出发日 ... -
AS3.0写的一个滚动条【缓动效果】
2008-06-13 16:10 6409package { import flash.d ... -
一个简单的文本滚动条类 as3
2008-06-13 16:04 4409最近一直做会议与AS3有关项目今天花了点时间写了一个可以选择套 ... -
自定义滚动条类
2008-06-13 16:01 2102在平常的开发中,经常需要用到滚动条,今天将滚动条类整理了下,有 ... -
AS3加载机制
2008-06-13 15:03 2229摸了好一阵子,才弄明白AS3.0的加载机制.还是坚持自己的原则 ... -
写了一个Flash的Transition
2008-06-11 10:36 1762写了一个Flash的Transition package { ... -
JavaScript与ActionScript函数相互调用
2008-06-06 15:07 22921、在JavaScript中调用Flex( ...
相关推荐
例如:`<embed src="your.mid" autostart=true loop=2>`、`<embed src="your.mid" autostart=true loop=true>` 和 `<embed src="your.mid" autostart=true loop=false>` 3. 面板显示:`hidden` 属性规定控制面板...
<embed src="your_swf_file.swf" width="640" height="480"> ``` 5. 兼容性问题:随着HTML5的兴起,许多现代浏览器不再支持Flash Player,因为HTML5提供了一套更安全、更高效的多媒体解决方案,如`<video>`和`...
`Embed`是AS3提供的一种机制,用于将外部资源(如图片、SWF文件等)嵌入到当前的Flash项目中。通过这种方式,开发者可以在运行时创建这些资源的实例并使用它们,而无需在Flash IDE中直接使用这些资源。 #### 三、...
在此示例中,`embed`标签被用来加载一个名为`clock.swf`的Flash文件。设置了`width`和`height`属性来定义播放器的尺寸,`quality`属性设为`high`以确保高质量的播放效果,`pluginspage`属性指定了获取Flash插件的...
<embed src="your.mid"> ``` ### 属性设置 1. **autostart**:设置媒体文件是否自动播放。 - `autostart="true"`:文件加载完成后立即播放。 - `autostart="false"`:文件加载完成后不会自动播放,需要用户手动...
<embed src="path_to_your_media_file" width="320" height="240"> ``` 这里的`src`属性指定了要加载的媒体文件的URL,`width`和`height`属性定义了媒体的显示尺寸。 ### 二、embed的属性 1. **src**:必需属性,...
<embed src="your_swf_file.swf" quality="high" pluginspage="http://www.adobe.com/go/getflashplayer" type="application/x-shockwave-flash" width="550" height="400"></embed> ``` 二、SWF的布局 1. **CSS...
在实际使用中,`<embed>`标签可用于嵌入多种类型的外部资源,包括但不限于Flash动画(如`.swf`文件)、音频文件、视频文件和其他可以利用相应插件播放的内容。然而,由于现代网页设计中越来越多的使用了`<video>`和`...
swfobject.embedSWF("focus.swf" , "index_focus" , "338px" , "245px" , "9.0.0" , "expressInstall.swf" , { "speed":"4000" ,"p":"74496849.jpg|74497030.jpg|67331658.jpg|67334584.jpg|67336998.jpg...
在ActionScript 3 (AS3)中,`Embed`元标签是一个非常有用的工具,它允许开发者将各种资源,如图片、字体等,直接内嵌到SWF文件中。这样做的好处在于,即使用户没有网络连接,也可以访问这些资源,提高了应用程序的...
1. **HTML嵌入SWF**:HTML页面通过`<object>`、`<embed>`或`<iframe>`标签来插入SWF文件。这些标签包含指向SWF文件的URL以及一些配置参数。 2. **HTTP请求与响应**:提取SWF文件前,需要发送HTTP GET请求到服务器...
在网页开发中,`<embed>` 标签用于嵌入外部资源,如音频、视频、插件等。本文将深入探讨如何动态修改 `<embed>` 元素的 `src` 属性,以及这样做带来的实际效果和应用场景。 动态修改 `src` 属性是网页交互中的常见...
标题“Embed Java VM in Executables using Java Native Interface (JNI)”指向一个实践教程或项目,其目标是将Java虚拟机(Java Virtual Machine, JVM)嵌入到可执行文件中。这通常是出于减少依赖性、提高启动速度...
[Embed(source="your_xml_file.xml", mimeType="application/xml")] public class EmbeddedXML extends Object { } ``` 这里的`source`属性指定要嵌入的XML文件路径,`mimeType`属性则指定了文件类型。这个`...
<embed src="path/to/your.swf" width="width" height="height" /> <!-- 更多 embed 参数配置 --> ``` 这样,当用户浏览器不支持 Flash 时,他们会看到这个替代内容。 5. **Flex 应用程序与 HTML 交互**: ...
<embed src="hamster.swf" width="400" height="300"> ``` 3. `<iframe>`标签:虽然不常用,但也可以用于嵌入SWF,尤其是在需要独立浏览环境的情况下。例如: ```html <iframe src="hamster.swf" width="400" ...
import "yourproject/resources" func main() { htmlContent := resources.IndexHtml // 使用htmlContent进行进一步处理... } ``` 4. 编译和运行:现在,当编译你的Go程序时,资源已经被内联到可执行文件中...
标题“Go-embed:另一个Golang静态内容嵌入器”暗示了`embed`包是Go语言中处理静态内容的一种方法。与其他第三方库相比,`embed`作为内置的解决方案,具有更好的性能和更低的依赖性。 描述“embed: 另一个Golang静态...
<mx:MovieClip id="swfPlayer" source="@Embed('path/to/your.swf')"/> ``` 2. **访问SWF的ActionScript API**: 一旦SWF文件被嵌入,我们可以通过引用`swfPlayer`的实例来访问其AS3 API。例如,要调用SWF中的...
SWF(ShockWave Flash)是一种由Adobe公司开发的富媒体格式,主要用于创建动画、交互式应用程序和网络游戏。在互联网的早期,SWF文件广泛应用于网页设计,因为它们能够提供丰富的用户体验,同时文件大小相对较小。...