mustella function implements to do this. * * * Sample usage: */ public function doResetOrientation():void { // if (aspectRatio != initialOrientation) // { // systemManager.stage.setAspectRatio(initialOrientation); // trace("current- "+ aspectRatio + " initial- "+initialOrientation); // } // else if (systemManager.stage.orientation != StageOrientation.DEFAULT) { systemManager.stage.setOrientation(StageOrientation.DEFAULT); } else systemManager.stage.dispatchEvent(new StageOrientationEvent('orientationChange')); } /** * This method gets all the current indices in view in groups in any layout */ public static function getIndicesInView(group:GroupBase):Vector. { var visibleIndices:Vector. = new Vector.(); var eRect:Rectangle = new Rectangle(); for (var i:int = 0; i < group.numElements; i++) { var e:IVisualElement = group.getElementAt(i); if (e != null) { eRect.x = e.getLayoutBoundsX(); eRect.y = e.getLayoutBoundsY(); eRect.width = e.getLayoutBoundsWidth(); eRect.height = e.getLayoutBoundsHeight(); if (group.scrollRect.intersects(eRect)) visibleIndices.push(i); } } return visibleIndices; } /* gets first item in view */ public static function getFirstInView(group:GroupBase):Number { return getIndicesInView(group).reverse().pop(); } /* gets last item in view */ public static function getLastInView(group:GroupBase):Number { return getIndicesInView(group).pop(); } /* gets center item in view */ public static function getCenterInView(group:GroupBase):Number { return (getFirstInView(group) + getLastInView(group)) /2; } /** * This method is used to find whether the current state in a list is leadingEdge aligned. * Takes the direction (vertical or horizontal) and DataGroup to validate that the scroll position is leading snapped. */ public static function isLeading(group:GroupBase, direction:String):String { if(direction=="vertical") { var top:Number= group.getElementAt(getIndicesInView(group).sort(Array.NUMERIC).reverse().pop()).getLayoutBoundsY(); var scrollPos:Number=group.verticalScrollPosition; if(-1<=(top-scrollPos)<=1) return "true"; else return top + "!=" + scrollPos; } if(direction=="horizontal") { var left:Number= group.getElementAt(getIndicesInView(group).sort(Array.NUMERIC).reverse().pop()).getLayoutBoundsX(); scrollPos=group.horizontalScrollPosition; if(-1<=(left-scrollPos)<=1) return "true"; else return left + "!=" + scrollPos; } return "incorrect direction"; } /** * This method is used to find whether the current state in a list is trailingEdge aligned. * Takes the direction (vertical or horizontal) and DataGroup to validate that the scroll position is trailing snapped. */ public static function isTrailing(group:GroupBase, direction:String):String { if(direction=="vertical") { var bottomElement:IVisualElement=group.getElementAt(getIndicesInView(group).sort(Array.NUMERIC).pop()); var bottom:Number=bottomElement.getLayoutBoundsY() + bottomElement.getLayoutBoundsHeight(); var scrollPos:Number=group.height+group.verticalScrollPosition; if(-1<=(bottom-scrollPos)<=1) return "true"; else return bottom + "!=" + scrollPos; } if(direction=="horizontal") { var rightElement:IVisualElement=group.getElementAt(getIndicesInView(group).sort(Array.NUMERIC).pop()); var right:Number=rightElement.getLayoutBoundsX() + rightElement.getLayoutBoundsWidth(); scrollPos=group.width+group.horizontalScrollPosition; if(-1<=(right-scrollPos)<=1) return "true"; else return right + "!=" + scrollPos; } return "incorrect direction"; } /** * This method is used to find whether the current state in a list is center aligned. * Takes the direction (vertical or horizontal) and DataGroup to validate that the scroll position is center snapped. */ public static function isCenterTile(group:GroupBase, direction:String):String { var firstInView:Number=getIndicesInView(group).sort(Array.NUMERIC).reverse().pop(); var lastInView:Number=getIndicesInView(group).sort(Array.NUMERIC).pop(); var centerInView:IVisualElement=group.getElementAt(((lastInView-firstInView)/2)+firstInView) if(direction=="vertical") { // # pixles below the center element var bottom:Number = (group.verticalScrollPosition + group.height)-(centerInView.getLayoutBoundsY()+centerInView.getLayoutBoundsHeight()); // # pixles above the center element var top:Number = centerInView.getLayoutBoundsY()-group.verticalScrollPosition; if(-1<=(top-bottom)<=1) return "true"; else return top + "!=" + bottom; } if(direction=="horizontal") { var right:Number = (group.layout.horizontalScrollPosition + group.width)-(centerInView.getLayoutBoundsX()+centerInView.getLayoutBoundsWidth()); // # pixles above the center element var left:Number = centerInView.getLayoutBoundsX()-group.layout.horizontalScrollPosition if(-1<=(left-right)<=1) return "true"; else return left + "!=" + right; } return "incorrect direction"; } ]]>