关于as3项目:有没有办法继承给定DisplayObject的属性?我正在寻找一个单一的方法,将抓住一些东西,如x,y,宽度,高度,颜色等。
..。
编辑:
我觉得我说得不够清楚...让我举一个我正在寻找的功能类型的例子。
var sp1:Sprite = new Sprite();
sp1.x = 30;
sp1.y = 30;
sp1.width = 500;
sp1.height = 30;
var tf1:TextField = new TextField();
tf1.inheritTransform(sp1);所以,在这种情况下,我知道'inheritTransform()‘方法不存在,但我想知道是否有类似的东西。或者,也许我在某种程度上错过了扩展类的要点?在这种情况下,我看不出两者之间有什么关系。
谢谢,jml
发布于 2009-12-22 02:46:53
首先,TextField是一个DisplayObject,所以它有x,y,width和height。
但是,如果我错了,请纠正我,如果你不想将属性从一个DisplayObject (或任何对象)“复制”到另一个,你可以手动完成,我认为没有“自动”的方法来做到这一点。您可以使用原型(或预制)来实现这一点,但您必须实现它。
您不能在运行时继承属性的值,您可以继承属性本身,但不能继承其值(如果属性是实例属性,如x。y、width和height)。
你可以做的另一件事是:
var s:Sprite = new Sprite()
s.x = 125
s.y = 200
var t:TextField = new TextField()
s.addChild(t) // here t transformation matrix is concatenated with s (because now t is inside s coordinate system because is a child of s)DisplayObject类的transform属性可能会对您有所帮助,该transform包含有关位置、旋转和缩放(以矩阵形式)的信息以及颜色信息。这可能会对你有帮助。
在您的示例中,您可以这样做:
var s:Sprite = new Sprite()
s.x = 30
s.y = 30
s.width = 500
s.height = 30
var t:TextField = new TextField()
t.transform = s.transform // this overrides the transform object, but sadly don't work with the width and height
t.width = s.width
t.height = s.height附言:很抱歉我的英语不好。
编辑:
您只能将addChild(和removeChild)与DisplayObjectContainer一起使用,请参阅http://livedocs.adobe.com/flex/3/html/help.html?content=05_Display_Programming_03.html
发布于 2009-12-21 17:11:42
Actionscript 3 language reference说明:
The DisplayObject class itself does not include any APIs for rendering content onscreen. For that reason, if you want create a custom subclass of the DisplayObject class, you will want to extend one of its subclasses that do have APIs for rendering content onscreen, such as the Shape, Sprite, Bitmap, SimpleButton, TextField, or MovieClip class.
https://stackoverflow.com/questions/1938347
复制相似问题