我正在尝试在ActionScript中设置FlexSprite对象的宽度/高度,但它似乎根本不起作用。在动作脚本方面,我仍然是新手,我不明白为什么我无法设置该对象的尺寸。我知道我可以使用UIComponent,但我需要更轻量级的东西,因为我要添加数百个。
public class MyComp extends UIComponent
{
public function MyComp()
{
super();
}
private var _sprite:FlexSprite;
private var _button:Button;
override protected function createChildren():void {
if (!_sprite) {
_sprite = new FlexSprite();
_sprite.width = 200;
_sprite.height = 200;
addChild(_sprite);
}
if (!_button) {
_button = new Button();
_button.label = "Click me";
_button.width = 150;
_button.height = 40;
addChild(_button);
}
super.createChildren();
}
override protected function measure():void {
measuredHeight = measuredMinHeight = 200;
measuredWidth = measuredMinWidth = 200;
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth,unscaledHeight);
trace('dimz of _sprite', _sprite.width, _sprite.height);
_sprite.width = 100; // doesn't work either
trace('dimz of _sprite again', _sprite.width, _sprite.height);
trace('dimz of _button', _button.width, _button.height);
}
}
我得到的输出是:
dimz of _sprite 0 0
dimz of _sprite again 0 0
dimz of _button 150 40
我计划在FlexSprite中添加其他对象,我还需要明确设置它们的尺寸,所以我真的需要弄清楚如何做到这一点。
答案 0 :(得分:2)
可能存在的一些问题:
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth,unscaledHeight);
_sprite.x = 10;
_sprite.y = 10;
_button.x = 400;
_button.y = 400;
}
我猜 - 但不知道b / c源是不可用的 - Sprite(FlexSprite扩展)正在重新调整它的子项;这是目前不存在的。