Aedis.Ju

2007年2月5日星期一

Sprites和Shapes的区别之一

为什么Button的mouseChildren是false呢?


mouseChildren顾名思义,就是这个存在在object的
孩子是否应该响应到mouse events事件
我们知道Button的组成包括了UITextField,另外包括了很多的skins和icons.

skins包括了upSkinName,overSkinName,downSkinName,disabledSkinName,selectedUpSkinName,selectedOverSkinName,selectedDownSkinName,selectedDisabledSkinName;
icons则包括了iconName,upIconName,overIconName,downIconName,disabledIconName,selectedUpIconName,selectedOverIconName,selectedDownIconName,selectedDisabledIconName.
skins和icons这些用户其实都是可以重新自定义的.

最主要的目的是为了保证mouse events是从Button它自己本身的触发,而不是它的skins,icons,UITextField.

我们在定义skins和icons的时候,会用到Sprites和Shapes,如果mouseChildren是true的话,用到Sprites的会无法响应click事件,Shapes还会是正常的.为什么呢?这是因为用到Sprites,做click事件的时候,它将直接响应到skins或者icons,而不是Button它本身,而Shapes是不会响应mouse events的.为了不让有这种情况发生,mouseChildren = false.

knowledge:

mouseChildren : BooleanDetermines whether or not the children of the object are mouse enabled.

Shape ---> DisplayObject --->EventDispatcher ---> Object
The Shape class is used to create lightweight shapes by using the ActionScript drawing application program interface (API). The Shape class includes a graphics property, which lets you access methods from the Graphics class. The Sprite class also includes a graphicsproperty, and it includes other features not available to the Shape class. For example, a Sprite object is a display object container, whereas a Shape object is not (and cannot contain child display objects). For this reason, Shape objects consume less memory than Sprite objects that contain the same graphics.

Sprite --->DisplayObjectContainer--->InteractiveObject ---> DisplayObject ---> EventDispatcher ---> Object
The Sprite class is a basic display list building block: a display list node that can display graphics and can also contain children. A Sprite object is similar to a movie clip, but does not have a timeline. Sprite is an appropriate base class for objects that do not require timelines. For example, Sprite would be a logical base class for user interface (UI) components that typically do not use the timeline.The Sprite class is new in ActionScript 3.0. It provides an alternative to the functionality of the MovieClip class, which retains all the functionality of previous ActionScript releases to provide backward compatibility.

没有评论: