2010-10-21 34 views
0

我想添加一個具有一些UI組件作爲孩子的容器到一個畫布,也希望設置邊界大小隻使用沒有MXML的動作腳本,我可以使用動作腳本將容器添加到Flex的畫布中嗎?

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); 

回答

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. 
相關問題