2009-08-28 1 views
2

나는 spark Scroller 내에 많은 자식 텍스트 입력을 가지고있다. 어떻게 A...d id를 가지고 있고, 스크롤바가 자동으로 그 자식 항목으로 스크롤 할 수 있다면 id가 "x"인 TextInput을 포커스로 만들 수 있습니까?플렉스 4 s : Scroller,보기에 포함 된 구성 요소를 가져 오는 방법?

x.setFocus()를 사용할 수 있지만 스크롤바가 자동으로 해당 항목으로 스크롤되지 않습니까? 왜?

<s:Scroller id="scroller" width="100%" height="100"> 
     <s:Group id="group" width="100%" height="100" id="content"> 
      <s:TextInput id="a" text="" editable="true" width="100%" height="25" /> 
      <s:TextInput id="b" text="" editable="true" width="100%" height="25" /> 
      .... 
     </s:Group> 
</s:Scroller> 

덕분에, 필립

답변

2

이유는 실제로 스크롤 바의 Parameters는 scrollPosition을 변경 이동하지 않습니다, setFocus void 현재는 단지 객체가 활성화됩니다 있다는 것입니다. List와 같은 좀 더 복잡한 클래스를 사용하면보다 직선적이지만 Scroller는 꽤 기본 적이기 때문에 좀 더 어렵습니다.

원하는대로하려면 뷰포트 (그룹) 내부에서 요소의 인덱스를 가져온 다음 scrollPosition을 수동으로 설정해야합니다. 수직 레이아웃의 코드는 다음과 같이 보일 것입니다 :

'g'는 당신이 당신의 스크롤러에로 이동하려는 요소의 ID입니다
var index:Number = group.getElementIndex(g); 
var offset:Number = group.getElementAt(index).height; 
scroller.viewport.verticalScrollPosition = index * offset; 

.

= 라이언 [email protected]

0

몇 가지 추가적인 고려 사항,보다 정확한 기준이 설정하는 경우 이잖아 그래서 만약 내 데이터 그룹의

  1. 그 항목은 일정한 높이 없습니다 스크롤러는 다음과 같습니다.

    var y : int = group.getElementAt (index) .y; scroller.viewport.verticalScrollPosition = y;

  2. 데이터 그룹이 가상화를 사용하도록 설정되어 있지 않은지 확인하십시오. 내 요소가 런타임에 추가/제거 될 때 오류가 발생했습니다.

1

그냥 당신의 DATAGROUP에 동일한 코드를 사용, 여기에 spark.components.List 방법입니다, 플렉스 SDK를 체크 아웃 :

public function ensureIndexIsVisible(index:int):void 
{ 
    if (!layout) 
     return; 

    var spDelta:Point = dataGroup.layout.getScrollPositionDeltaToElement(index); 

    if (spDelta) 
    { 
     dataGroup.horizontalScrollPosition += spDelta.x; 
     dataGroup.verticalScrollPosition += spDelta.y; 
    } 
} 
0

getScrollPositionDeltaToElement 방법은 중첩 된 아이들을 위해 고려하지 않습니다. 이를 위해 다음과 같이 mx_internal 메서드를 사용할 수 있습니다.

/** 
* Focus in handler to be used on form elements inside a Scroller. If the 
* widgets are inside a FormItem, this ensures that the entire FormItem is 
* scrolled into view. Also, if there are validations triggered on focusOut 
* of the elements, the default behavior in Flex 4 is to display the error 
* messages at the top of the form. Because this affects the vertical position 
* of each element, the logic to scroll the item into view must be delayed 
* until the next frame using callLater() 
* 
* NOTE: This uses a method, in the mx_internal namespace 
*/ 
    protected function widgetFocusInHandler(evt:FocusEvent):void { 
     //we need to delay this because we may need to account 
     //for validation errors being display above the form. 
     callLater(function(field:UIComponent) : void { 
      //find the form item that wraps the input and scroll 
      //it into view 

      var formItem:DisplayObjectContainer = field.parent; 
      while (!(formItem is FormItem) && formItem) { 
       formItem = formItem.parent; 
      } 

      //if this item wasn't in a form item, then just use the 
      //widget itself 
      if (!formItem) { 
       formItem = field; 
      } 

      var pt:Point = formItem.localToGlobal(new Point(0, formItem.height)); 

      pt = scrollWrapper.globalToLocal(pt); 
      var layout:LayoutBase = scrollWrapper.layout;   
      var delta:Point = layout.mx_internal::getScrollPositionDeltaToAnyElement(field); 
      if (delta) { 
       if(delta.y > 0) { 
        layout.verticalScrollPosition += delta.y + 20; 
       } else if (delta.y < 0) { 
        layout.verticalScrollPosition += delta.y - 20; 
       } 
      } 

     }, [UIComponent(evt.currentTarget)]); 
    } 
관련 문제