Jul 28

当比较两个字符串(String)时,使用 ‘==’ 运算子和 java.lang.String.equals()这个
method
有什么不同呢?

‘==’这个运算子会看看这两个字符串的references是不是指向同一个字符串object。而
java.lang.String.equals()
这个method则会比较这两个字符串的是不是一样的。换句
话说,比较这两个字符串是不是有相同的字符序列。

当使用String literals(一串被双引号括住的字符)时,使用 ‘==’运算子和使用equals
method
的结果会是一样的。所有的String literals都是指向同一个String 类别的
instances
。系统中有一个pool,当有新的String literals出现时,系统会先去检查pool
之中,是不是已经存在一个和这个新的String literals有相同内容的对象。如果存在,
则会传回一个指向这个此物件的reference。若不存在,则会将此String literals放到
pool
中,然后传回这个对象的reference

举个例子:
String s1 = “hello”;
String s2 = “hell”+”o”;
System.out.println(”Using equals op”+ (s1==s2)); //True
System.out.println(”Using equals method” + (s1.equals(s2))); //True

当字符串是由“new”这个关键词所造出来的时候,则不是这么一回事。

String s3 = new String(”hello”);
String s4 = new String(”hello”);
System.out.println(”Using equals op” + (s3==s4)); //False
System.out.println(”Using equals method” + (s3.equals(s4))); //True

传用“new”这个关键词时,会造出两个不同的对象,所以会有两个不同的references,即
使在底层的string literal是一样的。在上面的例子中,‘==’运算子传回false,因为两
references是不同的。而equals method则传回true,因为这两个对象所代表是同样的
字符序列。

Jul 23

Interfaces are a type of class that you design to act as an outline for your components. When you write an interface, you provide only the names of public methods rather than any implementation. For example, if you define two methods in an interface and then implement that interface, the implementing class must provide implementations of those two methods.

Interfaces in ActionScript can declare methods and properties only by using setter and getter methods; they cannot specify constants. The benefit of interfaces is that you can define a contract that all classes that implement that interface must follow. Also, if your class implements an interface, instances of that class can also be cast to that interface.

Custom MXML components can implement interfaces just as other ActionScript classes can. To do this, you use the implements attribute. All MXML tags support this attribute.    更多…… Continue reading »

Jul 21

同一个经过编码的字符串”%E4%BF%9D%E5%AF%86″
在fms2中经过unescape(”%E4%BF%9D%E5%AF%86″)处理后,结果是”保密”
在as3中经过unescape(”%E4%BF%9D%E5%AF%86″)处理后,结果是乱码
而经过decodeURI(”%E4%BF%9D%E5%AF%86″)处理后,结果却是”保密”.

引用luar的博客的原文:
在英文開發環境,未必容易察覺,因為AS1/2 escape()和AS3 escape() return相同結果,但是在double-byte文字,AS3 escape()終於跟JavaScript的做法相同,如果你要以前AS1/2的格式,你要用encodeURI()或者encodeURIComponent()。

ActionScript 1/2

var a:String = “香港:”; trace(escape(a)); // %E9%A6%99%E6%B8%AF%3A

ActionScript 3

var a:String = “香港:”; trace(escape(a)); // %u9999%u6E2F%3A trace(encodeURI(a)); // %E9%A6%99%E6%B8%AF: trace(encodeURIComponent(a)); // %E9%A6%99%E6%B8%AF%3A

JavaScript

var a = “香港:”; alert(escape(a)); // %u9999%u6E2F%3A alert(encodeURI(a)); // %E9%A6%99%E6%B8%AF: alert(encodeURIComponent(a)); // %E9%A6%99%E6%B8%AF%3A
Jul 01

var txt:Text=new Text();
txt.text=”textetxtxtjjjjjjjjjjjjjjjj”;
this.addChild(txt);
这时候txt的高度为0.

要获得高度
this.addEventListener(Event.RENDER,onAdded);
private function onAdded(e:Event):void{
    this.removeEventListener(Event.RENDER,onAdded);
    trace(txt.height);
}
别忘了removeEventListener,免得以后渲染(例如滚动)的时候继续执行