Browse > Home > Archive by category 'Flash CS3/AS3'

| Subcribe via RSS

AS3 Component: RichTextField

六月 25th, 2008 | 2 Comments , 932 views | Posted by flashlizi in Flash CS3/AS3

Just a very simple demo, welcome any feedback (bug or suggestion).

Demo Update:06-27
like MSN or QQ, you can input any content with smileys (click smileys to input) , then send it to the output window.

Official Flash Player 10(Astro) Documentation

五月 22nd, 2008 | No Comments , 258 views | Posted by flashlizi in Flash CS3/AS3

Download: Official Flash Player 10 Documentation
Extended read:
Flash Player 10 Drawing API

让timer事件不延迟第一次调度

四月 23rd, 2008 | No Comments , 303 views | Posted by flashlizi in Flash CS3/AS3

一般启动Timer对象创建计时器后,都要经过Timer.delay的延迟后才会第一次调度timer事件。不过有些时候,我们想不经过delay就第一次调度timer事件,因此我们可以扩展Timer类来实现:

package {
import flash.utils.Timer;
import flash.events.TimerEvent;
public class MyTimer extends Timer {
private var startDelay:Boolean;
public function MyTimer(delay:Number, repeatCount:int = 0, startDelay:Boolean = true) {
this.startDelay = startDelay;
super(delay, repeatCount);
}
public override function start():void {
if (!startDelay) dispatchEvent(new TimerEvent(TimerEvent.TIMER));
super.start();
}
}
}

使用方法:
//传入startDelay为false即不延迟调度timer事件
var timer:MyTimer = new MyTimer(1000, 5, false);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();

需要注意的是,不延迟第一次调度timer事件不会计入到计时器的总运行次数repeatCount的。即调度完第一次timer事件后,currentCount仍为0。

Batch convert files to Flashpaper2

三月 18th, 2008 | No Comments , 282 views | Posted by flashlizi in Flash CS3/AS3

Command:
FlashPrinter.exe {PATH TO DOCUMENT} -o {OUTPUT PATH & FILE with SWF extention}
Example:
FlashPrinter.exe riaidea.doc -o riaidea.swf

AS3 Library: ZipArchive 0.1 Release

三月 5th, 2008 | 7 Comments , 989 views | Posted by flashlizi in Flash CS3/AS3

ZipArchive是一个Zip档案处理类,可读写各种zip格式文件。(update version 0.11)

基本介绍:
1)轻松创建或加载一个zip档案;
2)多种方式读取和删除zip档案中的文件;
3)支持中文文件名;
4)非常容易序列化一个zip档案,如有AIR、PHP等的支持就可以把生成的zip档案保存在本地或服务器上。

更新:此项目已更新至0.2版本,请大家到http://code.google.com/p/as3-ziparchive/去下载最新的源码和示例。
下载:源文件+API文档+示例
查看:API文档

读取zip文件可查看下载包中的example示例。保存zip文件部分可参考我以前发布的AirZip功能演示。

下面是下载包中的example示例的部分代码:

public class Example extends Sprite {
private var zip1:ZipArchive = new ZipArchive();
public function Example() {
//加载一个zip档案
zip1.load(“test.zip”);
zip1.addEventListener(ProgressEvent.PROGRESS, loading);
zip1.addEventListener(ZipEvent.ZIP_INIT, inited);
zip1.addEventListener(ZipEvent.ZIP_FAILED, failed);
zip1.addEventListener(IOErrorEvent.IO_ERROR, ioError);
}
private function inited(evt:ZipEvent):void {
zip1.removeEventListener(ProgressEvent.PROGRESS, loading);
zip1.removeEventListener(ZipEvent.ZIP_INIT, inited);
zip1.removeEventListener(ZipEvent.ZIP_FAILED, failed);
//添加ZIP_CONTENT_LOADED事件侦听器
zip1.addEventListener(ZipEvent.ZIP_CONTENT_LOADED, imgloaded);
trace(“原始zip文件内容\r”, zip1);
//读取zip1中的xml文件
var xmlFile:ZipFile = zip1.getFileByName(“sample.xml”);
var xml:XML = new XML(xmlFile.data);
trace(xml);
//根据字符串内容创建一个新的txt文件
var txtContent:String = “这是一个测试文本文件”;
zip1.addFileFromString(“测试.txt”, txtContent);
//trace(zip1.getFileByName(“测试.txt”).data);
//复制zip1中的girl.jpg为张曼玉.jpg
var zmy:ZipFile = zip1.getFileByName(“girl.jpg”);
zip1.addFileFromBytes(“张曼玉.jpg”, zmy.data);
//加载zip1中的新生成的图片文件的Bitmap对象
zip1.getBitmapByName(“张曼玉.jpg”);
//删除图片文件logo.gif
zip1.removeFileByName(“logo.gif”);
trace(“\r修改后的zip文件内容\r”, zip1);
}
private function imgloaded(evt:ZipEvent):void {
zip1.removeEventListener(ZipEvent.ZIP_CONTENT_LOADED, imgloaded);
var img:Bitmap = evt.content as Bitmap;
addChild(img);
}
private function loading(evt:ProgressEvent):void {
//trace(evt.currentTarget, evt.bytesLoaded, evt.bytesTotal);
}
private function failed(evt:ZipEvent):void {
//trace(evt.content);
}
private function ioError(evt:IOErrorEvent):void {
//trace(evt);
}
}

一个命名空间namespace应用演示

二月 20th, 2008 | No Comments , 301 views | Posted by flashlizi in Flash CS3/AS3

这是一个用命名空间来控制名称相同的方法的不同实现的例子。三个命名空间string、number、array下均有一个名为print的方法,它们分别实现打印字符串、数字、数组的具体方法。有时候用命名空间也是实现方法重载的一种不错的办法。

演示代码如下:

  1. package {
  2. import flash.display.Sprite;
  3. public class NameSpaceExam extends Sprite{
  4. //打印字符串的NS
  5. private namespace string;
  6. //打印数字的NS
  7. private namespace number;
  8. //打印数组的NS
  9. private namespace array;
  10. //构造函数
  11. public function NameSpaceExam() {
  12. var str:String = "www.riaidea.com";
  13. var num:Number = 200802201507;
  14. var arr:Array = ["flash cs3", "flex3.0", "sliverlight 1.0", 2008, true];
  15. trace(string::print(str));
  16. trace(number::print(num,","));
  17. trace(array::print(arr));
  18. }
  19. //打印字符串
  20. string function print(str:String):String {
  21. return "String: " + str;
  22. }
  23. //打印数字,3节分段计数形式
  24. number function print(num:Number,sep:String=","):String {
  25. var str:String=String(num);
  26. var new_str:String="";
  27. var len:int=str.length;
  28. while(len>3){
  29. var tmp:String=str.slice(len-3);
  30. str=str.substring(0,len-3);
  31. new_str=sep+tmp+new_str;
  32. len=str.length;
  33. }
  34. return "Number: "+str+new_str;
  35. }
  36. //打印数组,枚举每个数组元素
  37. array function print(arr:Array):String {
  38. var str:String = "Array: \r";
  39. for (var i:int = 0, l:int = arr.length; i < l; i++) {
  40. str += "["+i+"]-> "+arr[i].toString()+"\r";
  41. }
  42. return str;
  43. }
  44. }
  45. }

输出结果为:

  1. String: www.riaidea.com
  2. Number: 200,802,201,507
  3. Array:
  4. [0]-> flash cs3
  5. [1]-> flex3.0
  6. [2]-> sliverlight 1.0
  7. [3]-> 2008
  8. [4]-> true

网页中flash对象ID命名错误造成ExternalInterface失效

二月 20th, 2008 | No Comments , 222 views | Posted by flashlizi in Flash CS3/AS3

今天做个小测试的时候,在flash cs3中按F12预览,发现ExternalInterface在IE下失效,而Firefox却很正常。以前做过类似的都没出现过问题。

经过排查,终于发现罪魁祸首是id="Untitled-1",把id中的连字符号(hyphen)去掉就OK了。大家都知道flash默认文件名为:Untitled-X.swf,测试也就没去修改。这样看来IE中的命名对连字符号"-"也是敏感的,最好避免在命名中使用到它。

IE7/Firefox阻止navigateToURL打开新窗口的解决方法

二月 13th, 2008 | No Comments , 504 views | Posted by flashlizi in Flash CS3/AS3

新年第一篇文章,首先给大家拜个晚年:)。今天上班终于想起要解决这个问题了。IE7和Firefox(我使用的版本是2.0.0.11)会阻止用navigateToURL方法打开新窗口,而AS2中的getURL方法则不会,让人很不爽。既然项目选择了AS3开发,就只能想办法来解决。

首先当然想到的是ExternalInterface了,测试发现还是会被blocked。后来想添加wmode会不会有所帮助,于是在页面中添加wmode属性为opaque,果然OK了。

现提供AS3中的getURL方法:

使用方法跟AS2中的getURL一样。另外,我只测试了IE6/7,Firefox2,并未对Safari等其他浏览器做测试。最后,最最重要的就是在html中把flash对象设置wmode属性为opaque或transparent。因为wmode属性默认为window,这表明此Flash应用程序与HTML层没有任何交互。

ActionScript代码显示器:ASFormatter

一月 24th, 2008 | 2 Comments , 304 views | Posted by flashlizi in Flash CS3/AS3

一个简单的ActionScript代码显示器。XML定义关键字、字符串、评论等的高亮,目前只定义了部分AS3的语法高亮,以后随着代码的添加需求再更新XML。AS代码存放在html页面的script的CDATA中。作用是仿照wordpress中的一个FlashTextEditor插件,用来在这个blog中贴AS代码。发现blog的ubbeditor和fckeditor的插入html代码的功能都不行后,我修改了博客程序,现在基本支持此功能了。以后贴的代码,阅读就方便多了。

下面随便贴段AS3代码来演示下:

FlashTail:简单实用的actionscript调试工具

八月 27th, 2007 | No Comments , 205 views | Posted by flashlizi in Flash CS3/AS3

Flash player的debuger版本有个功能,可以把flash文件中的trace信息输出到一个名为flashlog.txt的文本文件中,而且不管当前运行的flash所在的域如何或者是嵌在其他应用程序中,这些trace信息一律都会被记录在flashlog.txt中。因此我们可以利用这一特性,调试其他flash调试工具无法调试的flash程序。

首先要确认你的机器里安装了Flash player的debuger版本,检测办法:访问这里,右键点击中间那个flash(文字:Adobe Flash Player is installed.),如果在右键菜单中有“debuger”或者“调试器”的选项,则说明你已经安装了debuger版本。一般的如果你安装了flash 8或者flash cs3的话,都会自动安装了debuger版本。

接下来,新建一个mm.cfg文件。地址为:C:\Documents and Settings\username\mm.cfg,其中username为你的XP系统用户名,比如Administrator。打开mm.cfg,输入:

ErrorReportingEnable=0
TraceOutputFileEnable=1

然后,创建一个flashlog.txt文件。地址为:C:\Documents and Settings\username\Application Data\Macromedia\Flash Player\Logs\flashlog.txt,其中Logs目录需要自己创建的。这样,你机器上的flash文件里的trace信息就会保存在此文件中。但是,需要注意的是此文件只会保存最后打开的flash文件的trace信息。

为了使用方便,我做了一个监控和读取flashlog.txt文件内容的小工具:FlashTail。在你调试的时候,只要先把它打开,然后再打开需要调试的flash,FlashTail中就会把你的trace信息都显示出来。简单又非常方便,无需像其他debuger工具那样要在flash中添加调试代码,只需简单的trace()就OK!