我正在尝试将一个包含一些UI组件的容器添加到画布中,并且还希望仅使用没有MXML的动作脚本来设置边框大小,
1)是否可以在层次结构中添加从父级到子级的较低级别的容器,canvas addchild()可以将容器作为子级接受吗?
2)如何设置画布和容器的边框?
我需要在动作脚本中执行此操作我已经尝试过,但这里没有任何内容是代码: -
var contain:Container = new Container();
if(ename.text.length >0)
{
var newename:TextInput = new TextInput();
var newnamet:Label = new Label();
newnamet.text = namet.text;
newnamet.x = 5;
newename.text = ename.text;
newename.x = 100;
newnamet.y = newename.y = 20+contain.measuredHeight;
contain.addChild(newnamet);
contain.addChild(newename);
//contain.measure();
}//end if
contain.x=5;
contain.y =20+childcanvas.measuredHeight;
childcanvas.addChild(contain);
答案 0 :(得分:3)
取自文档:
The Container class is an abstract base class for components that controls the layout characteristics of child components. You do not create an instance of Container in an application. Instead, you create an instance of one of Container's subclasses, such as Canvas or HBox. The Container class contains the logic for scrolling, clipping, and dynamic instantiation. It contains methods for adding and removing children. It also contains the getChildAt() method, and the logic for drawing the background and borders of containers.