FLEX Data type 数据类型

Programming ActionScript 3.0 / ActionScript language and syntax / Data types -> Data type descriptions:
[url]http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_11.html[/url][quote]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[/quote]


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


类型检查:
[url]http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_09.html[/url][quote][b]The is operator[/b]
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 [b]instanceof[/b] 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

[b]The as operator[/b]
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
[/quote]


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


What's the difference between using 'as' keyword and regular typecasting like SomeType(foo)?
[url]http://www.flexfreaks.com/forums/viewtopic.php?id=5[/url][quote]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
[/quote]


[align=center][size=medium][color=red][b]区别与联系:Array & ArrayCollection & ArrayList[/b][/color][/size][/align]
当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:
[url]http://blog.152.org/2010/04/flex-copy-arraycollection.html[/url][quote]
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
[/quote]


ActionScript core 中的ArrayList和ArrayCollection两种类型的区别是什么?
他们的相同点是:都是以Array作为source来创建的;
不同点是:[quote][b][size=medium]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 [color=red]ArrayCollection has additional logic to sort and filter the list data[/color] however ArrayList is created specifically to hold and manipulate data and still be bindable. [color=red]Thus ArrayList is lighter version of ArrayCollection[/color].
Note: ArrayList is added in Flex 4 thus it will not be availalble in previous versions of flex sdk.[/size][/b][/quote]使用上也有些微的区别:[quote](i 为 索引值)
ArrayList和ArrayCollection中放的都是对象数组;但ArrayCollection既可以用source属性做遍历,也可以直接用arrayCollection[i]做遍历;而ArrayList是可以用source属性做遍历。
不过他们有个通用的遍历方式:
arrayCollectionOrArrayListInstance.getItemAt(i)
[/quote]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值