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

| Subcribe via RSS

Debug flash apps with firebug

03月 26th, 2009 | No Comments , 423 views | Posted by flashlizi in Flash CS3/AS3

大家应该都有用firebug的经验,现在提供2个类Console和Trace,Console可以将指定的debug的内容输出到firebug的控制面板,Trace则可以在firebug的console中trace页面中的flash里的对象和属性等。使用示例如下:
package
{
import flash.display.Sprite;
public class Main extends Sprite
{
public var version:String = "version 1.0";
public var info:Object = { name:"debug_demo", author:"alex", date:"2009-3-26" };
public function Main():void
{
Console.log("This a flash debug demo!");
Console.dump(info);
Trace.bind('main', this);
}
}
}

上面示例在firebug中的输出和trace截图如下:
firebug_screenshot

源文件和Demo下载>>>

用MSNContact Library获取MSN联系人列表

02月 25th, 2009 | 4 Comments , 666 views | Posted by flashlizi in Flash CS3/AS3

这是最近在做的一个项目中的一部分,功能就是根据你的MSN帐户和密码获取MSN好友列表。不过要注意因为此组件需要连接微软的MSN远程服务,所以会有安全沙箱问题,在debug状态或者添加了全局安全设置之后就不会报安全错误,当然最适合在AIR项目中使用了。
点击下载SWC组件>>

使用方法:
import com.riaidea.msn.MSNAccount;
import com.riaidea.msn.MSNContact;
var email:String = "your email address";
var password:String = "your msn password";
var account:MSNAccount = new MSNAccount(email, password);
account.addEventListener(Event.INIT, initHandler);

function initHandler(evt:Event):void
{
account.removeEventListener(Event.INIT, initHandler);
//在MSNAccount发出INIT事件后,即可用getContacts()方法获取Contact数组列表。
//数组的每个元素都是一个MSNContact对象,包含id,email,nickname三个属性。
for each(var c:MSNContact in account.getContacts())
{
trace(c); //或trace(c.id, c.email, c.nickname);
}
}

AS3类: BigInt(大整数)

02月 22nd, 2009 | No Comments , 1,532 views | Posted by flashlizi in Flash CS3/AS3

最近在一个项目中计算一个64bit的密钥key的时候,需要用到超过64位的数字运算。大家应该都知道,在AS3.0中,Number数据类型的范围是最大的,它可以使用52位来存储有效位数,即53位以上的数字只是近似值。因此需要到用到Big Integer(大整数),像目前的很多的RSA加密算法就建立于超过512位甚至更大的大数运算。网上找了一下只有hurlant的crypto加密库里面有com.hurlant.math.BigInteger这个类,可惜遗憾的是,这个类还是有位数限制,不能满足我的需求。因此我改写了一个BigInt的js类库,实现了简单的加减乘除取模等运算。由于时间比较紧,改写的代码比较乱,不过还是很好用的,现在分享给需要的朋友。点击下载>>>

下面是使用示例:
var x:BigInt = new BigInt("1234567890123456789012345678901234567890");
var y:BigInt = new BigInt("0x123456789abcdef0123456789abcdef0");
var z:BigInt = x.clone();//复制
z = x.negative();//取相反数
z = BigInt.plus(x, y);//加法
z = BigInt.minus(x, y);//减法
z = BigInt.multiply(x, y);//乘法
z = BigInt.divide(x, y);//除法
z = BigInt.mod(x, y);//取模
var compare:int = BigInt.compare(x, y); //大数比较 return -1, 0, or 1
var num:Number = x.toNumber(); //转为Number类型

Tags:

DebugLite: Make your debug life more easy!

01月 23rd, 2009 | No Comments , 336 views | Posted by flashlizi in Flash CS3/AS3

An agile actionscript3 debugger, you can play Eval function at first.

How to play Eval?

You can use actionscript code to access instances in this flash file, the available instances are main, main.tf, main.btn, main.check.  So you can try these actionscript codes in Eval box:
trace(main.tf.text,main.btn.label,main.check.selected);
main.btn.label=main.check.selected?"YES":"NO";
main.btn.dispatchEvent(new MouseEvent(MouseEvent.CLICK));

(note: enter these code into eval box in bottom, click eval button to see result.)

Please visit project homepage for more information.

Project homepage: http://code.google.com/p/debuglite/

Tags: , ,

GlowTween:一个发光的效果类

09月 9th, 2008 | 6 Comments , 695 views | Posted by flashlizi in Flash CS3/AS3

源文件(FlashDevelop项目)下载:

点击下载此文件

Camera.getCamera()的Bug

09月 8th, 2008 | No Comments , 377 views | Posted by flashlizi in Flash CS3/AS3

帮助文档上说:“如果 getCamera() 返回 null,则表明摄像头正由另一个应用程序使用,或者系统上没有安装摄像头。 ”而实际上是,只要系统上安装了摄像头,getCamera()都能返回摄像头,而不是返回null。搜索发现已经有人把这个bug报告给了adobe,不过到了flash player 10 依然没有修正。

另外,帮助文档说使用names.length来确定是否安装了任何摄像头,其实这个也是不能完全信任的。一个明显的bug就是不管你用getCamera()或是names.length都无法在Firefox中准确确定是否安装了摄像头,在安装了摄像头驱动但却没有连上摄像头或临时拔掉摄像头的情况下,上面两种方法都会返回已安装摄像头。不过,在IE下是正常的。

还有,如果用户安装了电视捕捉卡之类的,同样有可能被识别为camera对象,但实际上是无效的camera。

这里还有一些在使用camera的时候值得注意的问题:

Tip 1.

When initiating a connection to the Camera it’s best to do this through the Microphone class. Sounds odd I know! The reason for this is when this code is called :

var camera:Camera = Camera.getCamera();
ns.attachCamera(camera);

there’s a hang just after the allow button is selected on the security dialog panel. This is rationalled in the Adobe Flash help as ‘Scanning the hardware for cameras takes time’. So it’s best to trigger the security panel via

var microphone:Microphone = Microphone.getMicrophone();
ns.attachAudio(microphone);

then listen for the Status Event of UnMuted or later in your application call

var camera:Camera = Camera.getCamera();
ns.attachCamera(camera);

There will always be a delay on this code ns.attachCamera(camera); but at least via activating the Microphone first you won’t get a bug like delay of the security panel not disappearing immediately after the allow button is pressed.

Tip 2.

When recording to a Flash Media Server make sure the camera has activity via the Activity Status Event before publishing the stream. Otherwise you may get a static or black frame at the beginning of the recorded stream.

Tip 3.

To disable/turn off the Camera after a recording is complete do so via :

ns.attachCamera(null);

Though this is actually documented for AS3 it wasn’t in AS2. Once this has been done the Camera will need to be reconnected for a new recording and users will experience this delay again as the Camera starts as mentioned above.

Tip 4.

When embedding your Flash do not change the wmode from default. Otherwise you will get problems on specific browser configurations i.e. Firefox PC . These problems include that the allow button on the security dialog box will not hide on click.

Tip 5.

When detecting wether the user has a web camera you can’t rely on Camera.names.length(). This is because there are scenarios whereby devices will appear in the list which may not be webcameras but devices like TV capture cards and can not be used as a camera. The solution for this is when the camera is attached via

var camera:Camera = Camera.getCamera();
ns.attachCamera(camera);

Then add a time out catch which can be cleared via the camera’s activity event, so that if camera activity occurs within the time out of say 5 seconds then clear the timeout. Otherwise if the timeout happens handle the error scenario.

Tip 6.

Further to the above it’s good at the point of displaying the error message to give the user an option to fix this problem. This is because it may simply be a matter of the user changing the default camera selected. This can be done via adding a button and firing the Camera devices security dialog by the following :

Security.showSettings(SecurityPanel.CAMERA);

It’s interesting to know that when the user is selecting options from the Camera devices list it’s possible to detect wether the option selected is actually a Camera. Once again this is done via camera.activityLevel>0 on the Camera’s activity event. Sadly there is not yet a reliable way to detect when the dialog panel close event occurs. So with this in mind when the user has picked a camera, you should make a noticible visual change somewhere behind the dialog box (and overlay screen) so the user will proceed to the close button - happy days.

慎用正则表达式RegExp

08月 7th, 2008 | No Comments , 250 views | Posted by flashlizi in Flash CS3/AS3

AS3中的正则表达式效率并不高,在很多时候如果用其他方法能实现的话尽量不要用正则,所以String的replace、search、match如果有替换方法的话尽量不要用它们,比如用split&join方法代替一般replace。当然在一些用普通方法不好实现的复杂问题中用正则还是很好的。

比如下面的例子:
var str:String="i love flash-123";
test1(); //replace test1: 330 iloveflash
test2(); //strip test2: 67 iloveflash
function test1():void
{
var time=getTimer();
for(var i = 0; i < 1e4; i++)
{
str.replace(/\W|[0-9]|_/g, "");
}
trace("replace test1:", (getTimer()-time), str.replace(/\W|[0-9]|_/g, ""));
}
function test2():void
{
var time=getTimer();
for(var i = 0; i < 1e4; i++)
{
strip(str);
}
trace("strip test2:", (getTimer()-time), strip(str));
}
function strip(str:String):String
{
var newstr:String = "";
for (var i:int = 0, len:int = str.length; i < len; i++)
{
var char:String = str.charAt(i);
if (char >= “a”; && char <= "z") newstr += char;
}
return newstr;
}

AS3 Component: RichTextField

06月 25th, 2008 | 2 Comments , 648 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

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

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

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

04月 23rd, 2008 | No Comments , 212 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。

wow gold wow gold wow gold wow power leveling wow power leveling wow power leveling nike shoes nike shoes nike shoes nike shoes jordan shoes Jordan shoes jordan shoes Jordan shoes world of warcraft gold world of warcraft gold Replica handbags 1