2012-02-10 5 views
1

イベントのScrollerコンテナの表示可能なインデックスを変更しようとしています。 ScrollerにはImagesがあるHGroupが含まれているので、イベントではHGroupインデックスを指定してScrollerで表示できるImageを変更したいと思っています。これは可能ですか?Scrollerコンテナの位置をプログラムで変更する(HGroupインデックスによる)

コンテナコード:「BrigadeEmblem1は」スクローラに表示されている場合

ので
<s:Scroller id="test" includeIn="startState" x="53" y="20" width="170" 
      height="200" depth="2" scrollSnappingMode="leadingEdge"> 
    <s:HGroup gap="0" width="170" height="200"> 
     <s:Image id="BrigadeEmblem1" width="170" height="200" smooth="true" 
       smoothingQuality="high" source="assets/1st Stryker Brigade.png" 
       verticalAlign="middle"/> 
     <s:Image id="BrigadeEmblem4" width="170" height="200" smooth="true" 
       smoothingQuality="high" source="assets/4th Stryker Brigade.png" 
       verticalAlign="middle"/> 
    </s:HGroup> 
</s:Scroller> 

は、例えば、私は、特定のイベントが聞かれている場合、プログラム可視画像に「BrigadeEmblem4」に変更したいです。

答えて

0

まさにそれ!

setTimeout(image1,3000); // in 3 seconds this event will call for the function(image1) 

    function image1(){ 
    myMovieClip .visible = false; 
    } 
0

はい、実際これも可能です。

私はスクローラ-クラスを拡張し、この方法作成することでそれをやった:のために少し遅れて

myScroller.ensureIndexIsVisible(1); 
0

それはある:あなたが第二の画像が欲しいときに

public function ensureIndexIsVisible(index:int):void { 

     if (!viewport || !(viewport is GroupBase) || !(viewport as GroupBase).layout) { 
      return; 
     } 

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

     // if spDelta is null, no scrolling is required. 
     if (spDelta) { 
      GroupBase(viewport).horizontalScrollPosition += spDelta.x; 
      GroupBase(viewport).verticalScrollPosition += spDelta.y; 
     } 
    } 

を私はこれが誰かのために役立つことを願っています。私は、Scrollerを自動的にスクロールして、フォーカスされたコンポーネントが完全に見えるようにするコードを書いています。それを使って問題を解決することができます

private var _focusedComponentPaddingTop:int = 10; 
private var _focusedComponentPaddingBottom:int = 10; 
private var _focusedComponentPaddingLeft:int = 5; 
private var _focusedComponentPaddingRight:int = 5; 

public function makeFocusedItemVisible(event:FocusEvent):void { 
    // Target is the actual object that has focus. 
    var target:DisplayObject = DisplayObject(event.target); 

    if (target != null && contains(target)) { 
     // The container's viewable area 
     var visibleArea:Rectangle = getVisibleArea(); 
     var changed:Boolean = false; 

     // Calculate the position of the target in the container. 
     var topLeft:Point = new Point(0, 0); 
     topLeft = target.localToGlobal(topLeft); 
     topLeft = globalToLocal(topLeft); 

     var bottomRight:Point = 
      new Point(target.width, target.height); 
     bottomRight = target.localToGlobal(bottomRight); 
     bottomRight = globalToLocal(bottomRight); 

     // Check if the component is visible and move the scrollbars if not 
     if (bottomRight.x > visibleArea.right) { 
      var deltaX:Number = bottomRight.x - visibleArea.right; 
      viewport.horizontalScrollPosition += deltaX + _focusedComponentPaddingRight; 
      topLeft.x -= deltaX; 
      changed = true; 
     } 

     if (topLeft.x < visibleArea.left) { 
      viewport.horizontalScrollPosition -= 
       visibleArea.left - topLeft.x + _focusedComponentPaddingLeft; 
      changed = true; 
     } 

     if (bottomRight.y > visibleArea.bottom) { 
      var deltaY:Number = bottomRight.y - visibleArea.bottom; 
      viewport.verticalScrollPosition += deltaY + focusedComponentPaddingBottom; 
      topLeft.y -= deltaY; 
      changed = true; 
     } 

     if (topLeft.y < visibleArea.top) { 
      viewport.verticalScrollPosition -= 
       visibleArea.top - topLeft.y + focusedComponentPaddingTop; 
      changed = true; 
     } 

     // Call validateNow() to get the container move the component 
     if (changed) { 
      validateNow(); 
     } 
    } 
} 

private function getVisibleArea():Rectangle { 
    var area:Rectangle = new Rectangle(); 

    area.x = x; 
    area.y = y; 
    area.width = width; 
    area.height = height; 

    return area; 
} 
関連する問題