Flash AS3 精灵宽度在函数中不能正确发送
Flash AS3 sprite width does not send properly in function
我正在尝试将 sprite 发送到函数方法。
但是我无法获取 sprite 的宽度和高度。我不知道为什么会出现问题。
你能给我一个建议吗?
function mouseClick(evt:MouseEvent) { // click event
var s:Sprite = new Sprite();
s.width = 595;
s.height = 842;
s.x = s.y = 0;
addChild(s);
dothis(s);
}
function dothis(s:Sprite){
trace("s.width : "+s.width + " / s.height : "+s.height);
// s.width and s.height returns 0 value always..
}
如您所见,我得到的精灵的宽度和高度始终为 0 的结果。
为什么这会发生在我身上?
由于您的 Sprite
不包含任何内容(假设稍后会包含),因此 width/height 将始终为零。
Sprite -> DisplayObjectContainer -> InteractiveObject -> DisplayObject -> EventDispatcher -> 对象
如果您遵循 Sprite 对象继承,width/height 会暴露在 DisplayObject
class 中,并且根据 class:
中的注释
Except for TextField and Video objects, a display object with no content (such as an empty sprite) has a width of 0, even if you try to set width to a different value.
我正在尝试将 sprite 发送到函数方法。
但是我无法获取 sprite 的宽度和高度。我不知道为什么会出现问题。
你能给我一个建议吗?
function mouseClick(evt:MouseEvent) { // click event
var s:Sprite = new Sprite();
s.width = 595;
s.height = 842;
s.x = s.y = 0;
addChild(s);
dothis(s);
}
function dothis(s:Sprite){
trace("s.width : "+s.width + " / s.height : "+s.height);
// s.width and s.height returns 0 value always..
}
如您所见,我得到的精灵的宽度和高度始终为 0 的结果。
为什么这会发生在我身上?
由于您的 Sprite
不包含任何内容(假设稍后会包含),因此 width/height 将始终为零。
Sprite -> DisplayObjectContainer -> InteractiveObject -> DisplayObject -> EventDispatcher -> 对象
如果您遵循 Sprite 对象继承,width/height 会暴露在 DisplayObject
class 中,并且根据 class:
Except for TextField and Video objects, a display object with no content (such as an empty sprite) has a width of 0, even if you try to set width to a different value.