`

FLEX Data type 数据类型

    博客分类:
  • FLEX
阅读更多
Programming ActionScript 3.0 / ActionScript language and syntax / Data types -> Data type descriptions:
http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_11.html
引用
The primitive data types include Boolean, int, Null, Number, String, uint, and void. The ActionScript core classes also define the following complex data types: Object, Array, Date, Error, Function, RegExp, XML, and XMLList.

Subtopics

Boolean data type
int data type
Null data type
Number data type
String data type
uint data type
void data type
Object data type



Java与Flex类型转换对照关系:
Data Access and Interconnectivity / Accessing Server-Side Data with Flex -> Using RemoteObject components:
http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_4.html




类型检查:
http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_09.html
引用
The is operator
The is operator, which is new for ActionScript 3.0, allows you to test whether a variable or expression is a member of a given data type. In previous versions of ActionScript, the instanceof operator provided this functionality, but in ActionScript 3.0 the instanceof operator should not be used to test for data type membership. The is operator should be used instead of the instanceof operator for manual type checking, because the expression x instanceof y merely checks the prototype chain of x for the existence of y (and in ActionScript 3.0, the prototype chain does not provide a complete picture of the inheritance hierarchy).
var mySprite:Sprite = new Sprite();
trace(mySprite is Sprite); // true
trace(mySprite is DisplayObject);// true
trace(mySprite is IEventDispatcher); // true
The following example shows the same tests from the previous example, but with instanceof instead of the is operator. The instanceof operator correctly identifies that mySprite is an instance of Sprite or DisplayObject, but it returns false when used to test whether mySprite implements the IEventDispatcher interface.
trace(mySprite instanceof Sprite); // true
trace(mySprite instanceof DisplayObject);// true
trace(mySprite instanceof IEventDispatcher); // false

The as operator
The as operator, which is new in ActionScript 3.0, also allows you to check whether an expression is a member of a given data type. Unlike the is operator, however, the as operator does not return a Boolean value. Rather, the as operator returns the value of the expression instead of true, and null instead of false. The following example shows the results of using the as operator instead of the is operator in the simple case of checking whether a Sprite instance is a member of the DisplayObject, IEventDispatcher, and Number data types.
var mySprite:Sprite = new Sprite();
trace(mySprite as Sprite);                 // [object Sprite]
trace(mySprite as DisplayObject);                 // [object Sprite]
trace(mySprite as IEventDispatcher);                 // [object Sprite]
trace(mySprite as Number);                                       // null




默认值:
http://blog.csdn.net/firetaker/archive/2010/04/23/5519019.aspx




What's the difference between using 'as' keyword and regular typecasting like SomeType(foo)?
http://www.flexfreaks.com/forums/viewtopic.php?id=5
引用
The main difference between as operator and regular typecasting is the behavior when conversion fails. In Actionscript 3, when a typecast fails, TypeError error is thrown. Using the as keyword, the default value for that data type (usually null) is returned when cast fails. as is essentially like is. It does a type comparison, but instead of returning true or false, as returns the data or null on type mismatch.
var foo:Object = "bar";
trace( MovieClip ( o ) ); // TypeError thrown
trace(foo as ComboBox); // returns null






区别与联系:Array & ArrayCollection & ArrayList

当Array的数据发生变化的时候,用它作为数据源的控件不能感知这种变化;
而ArrayCollection和ArrayList在创建时均使用Array作为其参数source;可以让数据实现绑定;
ArrayCollection比ArrayList强的地方在于它有排序和过滤的功能,而ArrayList是没有的。
ArrayCollection类将Array公开为集合的封装,可用ICollectionView或IList接口的方法和属性处理;ArrayList可用IList接口的方法和属性处理封装的Array;
对ArrayCollection和ArrayList实例操作会修改原始数据。
Some tips:
使用 removeItemAt() 方法,就会删除基础 Array 中的项目。[/b]
Array.filter()会生成一个新的数组;而arrayCollection's filterFunction不会改变arrayCollection的source Array;
使用arrayCollection.toArray()会返回一个与原来arrayCollection的source不同的Array:
http://blog.152.org/2010/04/flex-copy-arraycollection.html
引用
var arrayCollection1:ArrayCollection = new ArrayCollection([1,2,3,4,5]);
var arrayCollection2:ArrayCollection = new ArrayCollection(arrayCollection1.toArray());
trace("arrayCollection1: " + arrayCollection1.toString());
trace("arrayCollection2: " + arrayCollection2.toString());
arrayCollection1.removeItemAt(0);
trace("arrayCollection1: " + arrayCollection1.toString());
trace("arrayCollection2: " + arrayCollection2.toString());
Output:
arrayCollection1: 1,2,3,4,5
arrayCollection2: 1,2,3,4,5
arrayCollection1: 2,3,4,5
arrayCollection2: 1,2,3,4,5



ActionScript core 中的ArrayList和ArrayCollection两种类型的区别是什么?
他们的相同点是:都是以Array作为source来创建的;
不同点是:
引用
ArrayList and ArrayCollection both can be used to store and manipulate list data. Both supports flex data binding which can drive the watching object to update itself on data change.
However the key difference between ArrayList and ArrayCollection is that ArrayCollection has additional logic to sort and filter the list data however ArrayList is created specifically to hold and manipulate data and still be bindable. Thus ArrayList is lighter version of ArrayCollection.
Note: ArrayList is added in Flex 4 thus it will not be availalble in previous versions of flex sdk.
使用上也有些微的区别:
引用
(i 为 索引值)
ArrayList和ArrayCollection中放的都是对象数组;但ArrayCollection既可以用source属性做遍历,也可以直接用arrayCollection[i]做遍历;而ArrayList是可以用source属性做遍历。
不过他们有个通用的遍历方式:
arrayCollectionOrArrayListInstance.getItemAt(i)


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics