flexpanel_node_get_child 함수 설명
flexpanel_node_get_child
함수는 주어진 부모 노드에서 자식 노드를 찾고 해당 자식 노드를 반환하는 기능을 합니다. 이 함수는 두 가지 유형의 값을 사용하여 자식 노드를 찾습니다:
- 인덱스:
flexpanel_node_insert_child
로 전달된 자식 노드의 인덱스 또는0
부터flexpanel_node_get_num_children - 1
까지의 값. - 이름: 자식 노드의 이름으로, 이는 초기 구조체의
name
속성을 통해 설정되거나flexpanel_node_set_name
을 통해 설정됩니다.
이 함수는 모든 자식 노드를 재귀적으로 검색하며, 첫 번째로 일치하는 노드를 반환합니다. 만약 자식 노드를 찾지 못하면 (예: 인덱스가 범위를 벗어나거나 이름이 발견되지 않은 경우) undefined
를 반환합니다.
함수 문법
flexpanel_node_get_child(node, index_or_name);
인수 설명
인수 | 유형 | 설명 |
---|---|---|
node | Flex Panel Node | 자식 노드를 가져올 부모 노드 |
index_or_name | Real 또는 String | 노드의 인덱스 또는 이름 |
반환값
- Flex Panel Node 또는 undefined
활용 예제
예제 1: 인덱스를 사용하여 자식 노드 가져오기
var parentNode = ...; // 부모 노드
var childIndex = 0; // 첫 번째 자식 노드의 인덱스
var childNode = flexpanel_node_get_child(parentNode, childIndex);
예제 2: 이름을 사용하여 자식 노드 가져오기
var parentNode = ...; // 부모 노드
var childName = "child1"; // 찾고자 하는 자식 노드의 이름
var childNode = flexpanel_node_get_child(parentNode, childName);
예제 3: 자식 노드가 없는 경우 처리하기
var parentNode = ...; // 부모 노드
var childIndex = 5; // 존재하지 않는 인덱스
var childNode = flexpanel_node_get_child(parentNode, childIndex);
if (childNode == undefined) {
show_message("자식 노드를 찾을 수 없습니다.");
}
예제 4: 모든 자식 노드에 대해 반복하기
var parentNode = ...; // 부모 노드
var numChildren = flexpanel_node_get_num_children(parentNode);
for (var i = 0; i < numChildren; i++) {
var childNode = flexpanel_node_get_child(parentNode, i);
// 자식 노드에 대한 작업 수행
}
예제 5: 이름으로 자식 노드 검색 후 작업 수행하기
var parentNode = ...; // 부모 노드
var childName = "child2"; // 찾고자 하는 자식 노드의 이름
var childNode = flexpanel_node_get_child(parentNode, childName);
if (childNode != undefined) {
// 자식 노드가 존재할 경우 작업 수행
}