[教程]将图片保存为swf文件的AIR

mikel阅读(1094)

Problem Summary

Saving images from AIR application in SWF format.

Solution Summary

Encode BitmapData to PNG or JPEG file, and load it to Loader using loadBytes method. After loading is completed you can pull out SWF data using bytes property of LoaderInfo class. This method works only in AIR applications.

Explanation

In AIR applications images loaded with Loader class are internally stored as a single frame, not compressed SWF file. As far as I know, this isn't documented anywhere, but it seems to work this way. This also fast way to convert local image file (png, jpg or gif) to swf format. We will use this method to create save local swf file from any image that is stored in BitmapData class instance.

 /* create bitmap to be saved as an swf file */
 var bd:BitmapData = new BitmapData(320,240);
 /* capture application snapshot, this can be any other object */
 bd.draw( Application.application as IBitmapDrawable );

When we have already created bitmap image we need to encode it to PNG or JPEG virtual file. Virtual means it will be stored in memory using ByteArray class. In example below we use mx.graphics.codec.PNGEncoder, to create virtual png file.

/* create virtual png file */
 var png:ByteArray = ( new PNGEncoder() ).encode( bd );

Last step is to use Loader class to load image. To load virtual png image stored in as instance of ByteArray class we must use loadBytes method. Listener function saveContentToSWF will be executed when load completes.

/* load virtual png image */
 var l:Loader = new Loader();
 l.contentLoaderInfo.addEventListener( Event.COMPLETE, saveContentToSWF );
 l.loadBytes( png );

When event is dispatched, our image is already converted to SWF file. Bytes stored in Loader class can be accessed with contentLoaderInfo.bytes property. To create and save local file we use File and FileStream classes. Lets put this all together now.

function saveContentToSWF( event : Event ):void
{
/* create output file on desktop */
var file:File = File.desktopDirectory.resolvePath('out.swf');
 var fs:FileStream = new FileStream(); fs.open( file, FileMode.WRITE );
/* pull out SWF bytes from Loader */
fs.writeBytes( (evt.target as LoaderInfo).bytes );
fs.close();
}

This method we will create local uncompressed SWF file. To decrease size we can also create compressed SWF file. To do this we must copy 8 byte header from uncompressed one. To indicate that file is compressed we must set first byte to value 0x43 (ascii code of letter 'C'). Entire file after first 8 bytes can be then compressed using compress method of ByteArray class. Puting this together we get new listener function, that creates compressed SWF files.

function saveContentToSWF_compress( event : Event ):void
{
 var file:File = File.desktopDirectory.resolvePath('out_c.swf');
 var fs:FileStream = new FileStream();
 fs.open( file, FileMode.WRITE );         
 /* compressed file header */
 var swf_head : ByteArray = new ByteArray();
 swf_head.endian = Endian.LITTLE_ENDIAN;
 swf_head.writeBytes( (evt.target as LoaderInfo).bytes, 0, 8 );
 swf_head[0] = 0x43; // 'C' letter, indicates that file is compressed
 swf_head.position = 0;
 /* compressed file body */
 var swf_body : ByteArray = new ByteArray();
 swf_body.endian = Endian.LITTLE_ENDIAN;
 swf_body.writeBytes( (evt.target as LoaderInfo).bytes, 8 );
 swf_body.position = 0;
 swf_body.compress();
 swf_body.position = 0;         
 /* write it down to file */
 fs.writeBytes( swf_head );
 fs.writeBytes( swf_body );
 fs.close();         
};

Example code using this technique is attached. Example application saves two SWF files compressed and uncompressed on users desktop.

Related files for download

save file, save image, save swf, swf, AIR, jpg, png
save_swf.zip

[工具]将GB转换为UTF-8的工具

mikel阅读(1011)

现在做的时候发现原来用的是gb编码,既然木已成舟,生米煮成熟饭,不如只转换涉及到的页面的编码了
于是,将包含的文件saveas后,找了个好用的工具,看来同病相连的人不少,呵呵….先一步写了工具
共产出来大家下载!
下载文件 点击下载此文件

[教程]ASP中UTF-8乱码

mikel阅读(757)

为什么在ASP里指定了codepage为65001还经常显示乱码。才子在这里将这个问题详细解释一下,以免很多朋友再走弯路,甚至排斥UTF-8。
如果你还不知道UTF-8是什么东东,那才子建议你先去搜索一下UTF-8的相关资料吧。
UTF-8编码之所以被越来越多的人接受甚至喜欢,肯定是有道理的,在WEB2.0盛行的今天,在大谈多浏览器兼容的同时,不得不想到字符编码不同所造成的乱码现象同样需要得到很好的处理…..
在N年以前,IE6以下的所有版本,只要没有安装相应的字库,访问相关的页面都是会乱码的,例如,我是IE5 (Windows2000默认) 的版本,在没有安装IE繁体字库的情况下,访问任何繁体页面的网站都是会乱码的,当然前提是该页面采用了BIG5的Charset,而UTF-8作为一种国际编码就能很好的处理该问题,只要将页面存为UTF-8编码格式,再在页面上将codepage及charset全部定义为utf-8就可以在任何客户端浏览器中显示出完全正确的内容,完全不会乱码……
好了,这里以ASP页面为例,以一个实例来看具体操作吧:
打开新建一个ASP页面,相信玩ASP的朋友都会留意到,许多下载的源码里,页面最上方一般都有一句:
以下为引用的内容:
%@LANGUAGE=”VBSCRIPT” CODEPAGE=”936″%
前面的language应该不用多说了,vbscript就是ASP默认的脚本语言,其实完全可以不用写,写了好像还会影响页面执行效率,在这里我们先不讨论这个问题。后面的codepage就是关键了,目的就是告诉浏览器,此页面是何种编码,936代表是简体中文,而950代表繁体中文, 65001就是我们今天说的UTF-8编码了。我们将936改成65001。整句如下:
以下为引用的内容:
%@LANGUAGE=”VBSCRIPT” CODEPAGE=”65001″%
再加上输出几个中文字看看能不能正确显示吧。
以下为引用的内容:
<% Response.Write "第一次测试UTF-8页面" %>
 
OK,直接点击“保存”,执行这个页面看看,如果不出意外,大家可能看到显示出的是 “一尾UTF-8页”这几个字,中文有乱码的现象,什么原因呢?
OK,请大家再点击最上面的 “文件” 菜单,选择”另存为”,最下面一行有个编码,默认应该是ANSI的,请大家点下拉框,选择UTF-8,再点保存,再执行试试看,如果不出意外,乱得更厉害了,呵呵,晕了吧。别急,想想原因,因为我们做的页面是HTML返回的,以前我们写HTML时,看到body前面,也就是head里都有一句meta,应该是这样的:
以下为引用的内容:

  
也就是指定页面以gb2312编码返回结果,一定要写在有返回结果输出的前面。大家都知道gb2312是简体中文吧,我们今天说的是UTF-8编码,我们就将gb2312改成UTF-8吧,全部代码如下:
以下为引用的内容:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<% Response.Write "第一次测试UTF-8页面" %>
  
再执行看看,嗯,这次正常显示了吧…….
结论:采用UTF-8编码,除了要将文件另存为UTF-8格式之外,还需要同时指定codepage及charset。

[代码]Javascript获取链接的文字内容

mikel阅读(886)

if (navigator.appName == "Microsoft Internet Explorer"){
document.getElementById("sayto").value=document.getElementById(lid).innerText;
}else{
document.getElementById("sayto").value=document.getElementById(lid).text;
}

[资源]程序员晋级教程

mikel阅读(783)

《J2EE 课程视频教程》赛迪网校罗泽彬老师主讲
http://www.beifengkd.com/read.php?tid=886&u=2660
《张孝祥JAVA视频教程》完整版[RMVB]
http://www.beifengkd.com/read.php?tid=422&u=2660
尚学堂148班高清晰版本Hibernate(王勇主讲)—共40集
http://www.beifengkd.com/read.php?tid=1338&u=2660
新东方J2ee系列
http://www.beifengkd.com/read.php?tid=531&u=2660
树人J2EE高级框架实战教学(视频教程)郭克华
http://www.beifengkd.com/read.php?tid=620&u=2660
MLDN J2EE 开发视频(共54讲)
http://www.beifengkd.com/read.php?tid=443&u=2660
北大青鸟 ASP.NET 视频(主讲:于海涛)共32 讲
http://www.beifengkd.com/read.php?tid=475&u=2660
达内anyfo–EJB视频第一集发布!!
http://www.beifengkd.com/read.php?tid=1329&u=2660
郭克华J2ME
http://www.beifengkd.com/read.php?tid=241&u=2660
H.S联盟VIP东西[黑客特训班]
http://www.beifengkd.com/read.php?tid=216&u=2660
oracle10g快捷版使用视频
http://www.beifengkd.com/read.php?tid=996&u=2660
参考资料:http://www.beifengkd.com/?a=ietjfdnv

[推荐]XSLT+XML创建WEB页面教程

mikel阅读(757)

现在越来越发现HTML其实是个很不怎么样的东西,尽管现在增加了CSS将样式分离了,可还是不可掩盖它丑陋的本质,尤其是数据的显示,干吗非得定义一套既定的什么table,div,ul,li……….来框住数据,数据是什么,数据是格式不固定的东西,我干吗非得要告诉你这个数据要用表格,哪个数据要用ul显示,我只需要给你一个我自己定义的xml数据文件,你用xslt看着办装饰就行了,因此发现html的末日基本上已成定局,还是xml+xslt来的干脆实际,正应了,让上帝的归上帝,凯撒的归凯撒那句化,数据和表现分离的如此彻底,想必这是html想都想不到的
学习网站:http://www.w3school.com.cn/

[推荐]HTML学习的网站

mikel阅读(806)

今天在Stumble Up看到一个推荐“HTML Playground”。虽然是2006年的作品,个人认为是目前为止看到的最好的学习HTML的资源。尤其是对于那些追求更好的语义化HTML产品的工程师,这个网站实在是一大福音。

如果感兴趣,现在就打开这个网站新窗口打开)看看哦。我发现深入细节之后,自己的HTML还有很多潜力可以挖掘:)

关于这个网站的使用方法,我简单描述一下:

  1. 在左上角,用鼠标选择一个HTML标签。

  2. 右上角会出现这个标签的含义。例如你选择“<tfoot>”,右侧会出现:

    Defines a table footer. The thead, tfoot and tbody elements enable you to group rows in a table. When you create a table, you might want to have a header row, some rows with data, and a row with totals at bottom. This division enables browsers to support scrolling of table bodies independently of the table header and footer. When long tables are printed, the table header and footer information may be repeated on each page that contains table data.

    我简单翻译一下:(<tfoot>)定义一个table的底。thead、tfoot和tbody元素能让你为一个table分排(上 中下)。因为,当你创建一个table的时候,你也许需要一个表头、内容和一个表尾(三排)。这样做的好处是,当一个table被打印时,表头和表尾会在 每一页重复出现(内容在中间循环),这样用户看起来就会更加清晰。

  3. 右下角有一个“Example Code”,这里面的内容可以即使编辑并在右侧看到效果,这一点类似Firebug的HTML Edit工具。对于一次性修改多处HTML、CSS非常有用。

  4. 左下角是当前标签所能支持的各种属性。可以动态地修改以观察效果。类似3

我有一点感慨:现在Web开发的门槛随着Google AppEngine和大量的JavaScript开发库的涌现,已经非常低了。使用Google AppEngine(目前仅Python)和JQuery,可以很快的构建一套自己的Web服务。而开发者只需用到一些简单的Python、 JavaScript知识来分别处理服务器端和前端的逻辑。而类似“HTML Playground”这些优秀的智能教程也在逐渐出现,Web开发本身会不会在未来成为一门“基本技能”呢?

可以说,快速、高效的Web开发如果成为一种基本技能,必然会给其他行业带来极大的(方)便利(益)。而(开发者)如何向第三方(使用Web开发受益的传统行业)索取回报,也许是未来一个有趣的话题。

[教程]VS2008中ASP.net中应用FCKEditor

mikel阅读(776)

http://blog.blueshop.com.tw/topcat/archive/2006/11/30/45727.aspx
1.下载Fckeditor标准版这个很重要因为需要里面的html和js文件,解压
2.下载Fckeditor.net压缩包,解压缩
3.在vS2008中新建WebSite项目
4.引用fckeditor.net\bin\Release\2.0\FredCK.FCKeditorV2.dll
5.拷贝步骤一中解压的fckeditor文件夹到website项目根目录这点很重要,因为fckeditor默认读取根目录下的fckeditor文件夹的html和js
6.添加到工具箱


选择浏览,选择fckeditor.net\bin\Release\2.0\FredCK.FCKeditorV2.dll,然后单击打开

这样就可以看到fckeditor被加入framework组件中

工具栏中出现fckeditor组件,就可以拖拽到页面上进行可视化编辑了

[代码]AIR的配置文件解析

mikel阅读(933)

今天对AIR安装配置文件做了一下研究,发现有很多细致配置的东西,把自动生成的文件添加了中文注释.相信对正在做AIR项目的人能够有所帮助.

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://ns.adobe.com/air/application/1.0">
<!-- The application identifier string, unique to this application. Required. -->
<id>AIRTest1</id><!-- 软件ID,当安装时系统将会检测同一ID软件版本,版本高的即做更新操作 -->
<!-- Used as the filename for the application. Required. -->
<filename>AIRTest_filename</filename><!-- 安装界面中 Application: -->
<!-- The name that is displayed in the AIR application installer. Optional. -->
<name>AIRTest_name</name><!-- 桌面快捷方程式及窗口和系统控制面板添加程序中名称 -->
<!-- An application version designator (such as "v1", "2.5", o&#114; "Alpha 1"). Required. -->
<version>1.0</version><!-- 软件版本 -->
<!-- Description, displayed in the AIR application installer. Optional. -->
<description>AIRTest_description</description><!-- 安装第二个界面中的 description -->
<!-- Copyright information. Optional -->
<copyright>AIRTest_copyright</copyright>
<!-- Settings for the application&#39;s initial window. Required. -->
<initialWindow>
<!-- The main SWF o&#114; HTML file of the application. Required. -->
<!-- Note: In Flex Builder, the SWF reference is set automatically. -->
<content>[This value will be overwritten by Flex Builder in the output app.xml]</content>
<!-- The title of the main window. Optional. -->
<title>AIRTest_title</title><!-- 窗体标题,当此处为注释状态时取 name标签中内容 -->
<!-- The type of system chrome to use (either "standard" o&#114; "none"). Optional. Default standard. -->
<systemChrome>none</systemChrome><!-- standard为标准窗体,none 为圆滑窗体 -->
<!-- Whether the window is transparent. Only applicable when systemChrome is false. Optional. Default false. -->
<transparent>true</transparent><!-- 背景是否透明 -->
<!-- Whether the window is initially visible. Optional. Default false. -->
<visible>true</visible><!-- 窗体初始化的时候是否可见 -->
<!-- Whether the user can minimize the window. Optional. Default true. -->
<minimizable>true</minimizable><!-- 是否允许最小化 -->
<!-- Whether the user can maximize the window. Optional. Default true. -->
<!-- <maximizable></maximizable> --><!-- 是否允许最大化 -->
<!-- Whether the user can resize the window. Optional. Default true. -->
<!-- <resizable></resizable> --><!-- 是否允许缩放窗体 -->
<!-- The window&#39;s initial width. Optional. -->
<!-- <width></width> --><!-- 窗体宽 -->
<!-- The window&#39;s initial height. Optional. -->
<!-- <height></height> --><!-- 窗体高 -->
<!-- The window&#39;s initial x position. Optional. -->
<!-- <x></x> --><!-- 窗体X位置坐标 -->
<!-- The window&#39;s initial y position. Optional. -->
<!-- <y></y> --><!-- 窗体Y位置坐标 -->
<!-- The window&#39;s minimum size, specified as a width/height pair, such as "400 200". Optional. -->
<!-- <minSize></minSize> --><!-- 窗体最小化值 -->
<!-- The window&#39;s initial maximum size, specified as a width/height pair, such as "1600 1200". Optional. -->
<!-- <maxSize></maxSize> --><!-- 窗体最大化值 -->
</initialWindow>
<!-- The subpath of the standard default installation location to use. Optional. -->
<installFolder>AIRInstrallField/AIR</installFolder><!-- 默认安装路径 C:\Program Files\AIRInstrallField\AIR -->
<!-- The subpath of the Windows Start/Programs menu to use. Optional. -->
<programMenuFolder>AIRTest_programMenuFolder</programMenuFolder><!-- 开始/程序 快捷方程式所在文件夹 -->
<!-- The icon the system uses for the application. For at least one resolution,
specify the path to a PNG file included in the AIR package. Optional. -->
<!-- 图标的大小必须和标签中标写的尺寸一致 -->
<icon>
<image16x16>icons/logo.png</image16x16><!-- 系统菜单中及系统控制面板添加程序中的图标 -->
<image32x32>icons/logo_32.png</image32x32><!-- 桌面图标,窗口图标 -->
<image48x48>icons/logo_48.png</image48x48><!-- 安装目录EXE文件图标 -->
<image128x128>icons/logo_128.png</image128x128><!-- 未知 -->
</icon>
<!-- Whether the application handles the up&#100;ate when a user double-clicks an up&#100;ate version
of the AIR file (true), o&#114; the default AIR application installer handles the up&#100;ate (false).
Optional. Default false. -->
<!-- <customUp&#100;ateUI></customUp&#100;ateUI> --><!-- 是否为同一版本的时候双击直接更新 -->
<!-- Whether the application can be launched when the user clicks a link in a web browser.
Optional. Default false. -->
<!-- <allowBrowserInvocation></allowBrowserInvocation> --><!-- 是否应用程序可以通过浏览器激活 -->
<!-- Listing of file types for which the application can register. Optional. -->
<!-- <fileTypes> -->
<!-- Defines one file type. Optional. -->
<!-- <fileType> -->
<!-- The name that the system displays for the registered file type. Required. -->
<!-- <name></name> -->
<!-- The extension to register. Required. -->
<!-- <extension></extension> -->
<!-- The description of the file type. Optional. -->
<!-- <description></description> -->
<!-- The MIME type. Optional. -->
<!-- <contentType></contentType> -->
<!-- The icon to display for the file type. Optional. -->
<!-- <icon>
<image16x16></image16x16>
<image32x32></image32x32>
<image48x48></image48x48>
<image128x128></image128x128>
</icon> -->
<!-- </fileType> -->
<!-- </fileTypes> -->
</application>

[新闻]Thermo预览

mikel阅读(696)

Adobe MAX 2008 is going to be highlighting a new RIA product codenamed "Thermo". Working with the product development team directly I was able to get some exclusive screenshots of "Thermo". Make sure to take a look at the higher resolution images (linked). We will see a ton of "Thermo" at Adobe MAX 2008, see you there!





See you at Adobe MAX 2008!