ActionScript 3 放大Scroller视口中缩放容器内TextFlow中的链接

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 放大Scroller视口中缩放容器内TextFlow中的链接相关的知识,希望对你有一定的参考价值。

private function moveAndZoomToLink(link:LinkElement,p:Person):void
			{
				var linkStart:int = link.getAbsoluteStart();
				var textFlowLine:TextFlowLine = textFlow.flowComposer.findLineAtPosition(linkStart);
				var linkPositionOnLine:int = linkStart-textFlowLine.absoluteStart;
					
				var controllerIndex:int = textFlow.flowComposer.findControllerIndexAtPosition(linkStart);
				var controller:ContainerController = textFlow.flowComposer.getControllerAt(controllerIndex);
				var containerSprite:Sprite = controller.container;
				
				var rect:Rectangle = textFlowLine.getBounds();
				var atomRect:Rectangle = textFlowLine.getTextLine().getAtomBounds(linkPositionOnLine+1);
				var nameWidth:Number = p.firstName.length*atomRect.width;
				
				var globalAtomRect:Rectangle = new Rectangle(rect.x+(atomRect.x-atomRect.width),rect.y,nameWidth,rect.height);
				
				var box:Shape = new Shape();
				box.graphics.beginFill(0xff0000,0.3);
				box.graphics.drawRect(globalAtomRect.x,globalAtomRect.y,globalAtomRect.width,globalAtomRect.height);
				containerSprite.addChild(box);
				
				var localPosition:Point = new Point();
				localPosition.x = containerSprite.x+rect.x+globalAtomRect.x;
				localPosition.y = containerSprite.y+rect.y;
				
				/*
					We're zooming in so scale the local position
				*/
				var scaledX:Number = localPosition.x*Config.SHIRT_ZOOM_SCALE;
				var scaledY:Number = localPosition.y*Config.SHIRT_ZOOM_SCALE;
				
				/*
					We don't want the shirt to move so it is out of the viewport so calculate what this range is ...
				*/
				
				var maxMoveX:Number = (Config.SHIRT_WIDTH*Config.SHIRT_ZOOM_SCALE)-Config.VIEWPORT_WIDTH;
				var maxMoveY:Number = (Config.SHIRT_HEIGHT*Config.SHIRT_ZOOM_SCALE)-Config.VIEWPORT_HEIGHT;
				
				var newX:Number = 0-scaledX;
				var newY:Number = 0-scaledY;
				
				var centeredX:Number = newX+Config.VIEWPORT_CENTER_X;
				var centeredY:Number = newY+Config.VIEWPORT_CENTER_Y;
				
				/*
					Check the shirt hasn't moved out of bounds
				*/
				
				var offsetX:Number = centeredX>0? centeredX*-1 : centeredX<0-maxMoveX? (centeredX*-1)-maxMoveX : 0;
				var offsetY:Number = centeredY>0? centeredY*-1 : centeredY<0-maxMoveY? (centeredY*-1)-maxMoveY : 0;
				
				/*
					Finally, the new position is nudged so it is at the centre of the viewport space or as near as can be.
				*/
				moveToPointX = centeredX>0? 0 : centeredX<0-maxMoveX? centeredX+((centeredX*-1)-maxMoveX) : centeredX;
				moveToPointY = centeredY>0? 0 : centeredY<0-maxMoveY? centeredY+((centeredY*-1)-maxMoveY) : centeredY;
				
				var viewportX:Number = Config.VIEWPORT_CENTER_X+offsetX;
				var viewportY:Number = Config.VIEWPORT_CENTER_Y+offsetY;
				
				shirtMoveTo.play();
				
				var evt:PersonSelectionEvent = new PersonSelectionEvent(PersonSelectionEvent.PERSON_SELECTION,true);
				evt.viewportPoint = new Point(viewportX,viewportY);
				evt.person = p;
				
				dispatchEvent(evt);
			}

以上是关于ActionScript 3 放大Scroller视口中缩放容器内TextFlow中的链接的主要内容,如果未能解决你的问题,请参考以下文章

SWFLoader 上的 Actionscript 3 和 Flex 4 缩放手势

如何使用 actionscript 3 将 ascii 文件加载到数组中

Android自定义View Scroller与平滑滚动

Android自定义View Scroller与平滑滚动

站在源码的肩膀上全解Scroller工作机制

使用Scroller制作滑块开关ToggleButton