Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3显示对象高度未正确报告_Actionscript 3_Displayobject - Fatal编程技术网

Actionscript 3 AS3显示对象高度未正确报告

Actionscript 3 AS3显示对象高度未正确报告,actionscript-3,displayobject,Actionscript 3,Displayobject,这应该很简单。我错过了什么? 创建一个Sprite容器,将其放在显示列表中,向容器添加一个新的Sprite rect。 更改子矩形的高度。 虽然正确呈现,但未正确报告父容器和子rect的高度值。 谢谢你的帮助 var container:Sprite = new Sprite(); addChild(container); [Embed(source = "../lib/rectangle.swf")] // height is 100 var Rect:Class; var rect:Spr

这应该很简单。我错过了什么? 创建一个Sprite容器,将其放在显示列表中,向容器添加一个新的Sprite rect。 更改子矩形的高度。 虽然正确呈现,但未正确报告父容器和子rect的高度值。 谢谢你的帮助

var container:Sprite = new Sprite();
addChild(container);

[Embed(source = "../lib/rectangle.swf")] // height is 100
var Rect:Class;
var rect:Sprite = new Rect();

trace(rect.height); // 100 is correct before placement in container
container.addChild(rect);
trace(rect.height); // 100 is correct after placement in container
trace(container.height); // 0 is not correct; should be 100

rect.height = rect.height + 100; // renders correctly at new height
trace(rect.height); // 100 is not correct; should be 200
trace(container.height); // 0 is not correct; should be 200
显然,您的容器不在舞台展示列表中。如果测量的显示对象不在显示列表中的任何位置,则在更改其自己的显示列表时,其标注特性不会正确重新计算。这显然是为了节省时间,让Flash引擎更快地处理复杂MovieClip帧或任何其他复杂容器的构建,并且只有当容器被放置到后台时才进行重新计算。分辨率是将要测量的对象放置在舞台的任何位置,无论如何,收集其属性,然后将其从舞台上移除。例如:

trace(this.stage); // [object Stage] - to make sure we can access stage in here
var sp:Sprite=new Sprite();
var b:Bitmap=new Bitmap(new BitmapData(100,100)); 
trace(sp.width); // should return 0
trace(sp.height); // 0 also
sp.addChild(b);
trace(sp.height); // 0 again
trace(b.height); // should return 100, as the bitmap data is specified
// as well as in your case, the class's width and height are precalculated
addChild(sp);
trace(sp.height); // returns 100, as expected
removeChild(sp);
trace(sp.height); // 100, stored
sp.removeChild(b);
trace(sp.height); // should also return 100, while there's no content in the sprite

还有另一种可能性,舞台外对象的宽度可以是,解决方案也是一样的-将对象放在舞台上,获得宽度,从舞台上移除对象。

您说的是精灵容器中的精灵矩形,但您的示例显示了精灵中的SWF。SWF中有什么?它是否覆盖大小属性?SWF是填充矩形的矢量图形。它的高度是100px,宽度是4px。我不知道嵌入的SWF对sprite属性有什么影响。如果在AS3中更改了精灵的属性,精灵将正确渲染。嵌入的swf将作为二进制文件嵌入,因此其行为略有不同。如果您创建它的克隆,那么该克隆将正常工作。