troubleshooting Question

Find Middle of line

Avatar of GTsafas
GTsafas asked on
Adobe Flash
7 Comments2 Solutions278 ViewsLast Modified:
I need to find the middle of this line and follow it.

When I move the mouse I want an item to follow along the center of the line that corresponds with the mouses x. I dont care if this is the whole stage or just when the mouse is inside the line itself.

But it needs to give leeway from the center, so that you dont have to trace it exactly.


Any help is appreciated, thanks




package 
{
	import flash.display.*;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
 
	public class Main extends Sprite 
	{
		
		public function Main():void 
		{
			
			
					
 
				var lineDrawing:Sprite = new Sprite();
				lineDrawing.graphics.lineStyle(80, 0x0000FF);
				lineDrawing.graphics.moveTo(0,0); 
				lineDrawing.graphics.lineTo(350, 600);
				lineDrawing.graphics.lineTo(600, 400);
				lineDrawing.addEventListener(MouseEvent.MOUSE_MOVE, mse_over);
				addChild(lineDrawing);
				 
 
		//		var square:Sprite = new Sprite();
		//		addChild(square);
			//	square.graphics.lineStyle(3,0x00ff00);
				//square.graphics.beginFill(0x00ff00);
				//square.graphics.drawRect(10,45,75,10);
				//square.graphics.endFill();
				
				var label:TextField = new TextField();
				addChild(label);
				
				
				function mse_over(event:MouseEvent):void
					{
							label.autoSize = "left";
							label.text = mouseX.toString() + "," + mouseY.toString();
							//label.x = ;
							//label.y = "";
							square.x = 5 + mouseX;
							square.y = mouseY - 66;
					}
	}
}}
ASKER CERTIFIED SOLUTION
Gary Benade

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros