2011-09-22 2 views
1

FlashBuilder의 스테이지에서 7 개의 TextAreas를 가져 오려고합니다. 모두 ID가 "Desc1", "Desc2", "Desc3"입니다. .와 이름이 같은 "Desc1"있다 "고 설명 2", "Desc3"...,하지만 난 그것을 얻을하려고 할 때, 내가 널 객체의 오류가 ...스테이지에서 TextArea 가져 오기 (ID, 이름 별 getChild)

for(var i:int = 0;i<7;i++) 
{ 
    trace((stage.getChildByName("Desc"+(i+1))as TextArea).x); 
} 

내가 검색 웹은 "getChildByID"의 메소드를 찾지 않습니다.

+0

"stage.numChildren"추적 - 얼마나 많은 항목이 보입니까? 확률은 TextAreas가 스테이지의 직접 자식이 아니지만 다른 객체 내에 중첩되어 있다는 것입니다. getChildByName은 스테이지 아래에있는 모든 하위 항목을 자세히 검색하지 않습니다. – meddlingwithfire

답변

0

getChildByName()에서는 플렉스 ID가 작동하지 않습니다. getChildByName()은 Adobe Flash CS에서 중첩 요소의 ID를 사용하도록 설계되었습니다.

flex id는 id와 동일한 이름을 가진 클래스 멤버의 명시 적 선언입니다. actionscript laguage에서 매크로가 없기 때문에 이러한 컨트롤 목록을 만들 수 없습니다.

당신은 수동으로 벡터 또는 텍스트 영역의 배열을 생성하고 자동으로 텍스트 영역을 반복하는 코드의 다른 부분에서 사용할 수 있습니다

:

var text_areas:Vector.<TextArea> = new Vector.<TextArea>(); 
text_areas.push(Desc1, Desc2, Desc3); 
// or you can do this 
var text_areas2:Array = []; 
text_areas["Desc1"] = Desc1; 
text_areas["Desc2"] = Desc2; 
text_areas["Desc3"] = Desc3; 
// Now you can iterate over the text areas 
for each (var a_text_area:TextArea in text_areas) 
{ 
    .... 
} 

아니면 플렉스 배열을 만들 수 있습니다

<fx:Array id="textAreas"> 
    <s:TextArea id="textArea1"/> 
    <s:TextArea id="textArea2" x="397" y="0"/> 
    <s:TextArea id="textArea3" x="201" y="1"/> 
</fx:Array>