Link to home
Start Free TrialLog in
Avatar of GTsafas
GTsafas

asked on

Find Middle of line

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;
					}
	}
}}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gary Benade
Gary Benade
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
do you need any more help with this?
My code does exactly what you asked it to do, the fact that you found another solution after ignoring the question for more than a month doesn't change the fact that the answer is correct.

A considerable amount of work went into coding that for you and if you don't appreciate it someone else no doubt will at some point in the future
Avatar of GTsafas
GTsafas

ASKER

Im sorry, it did not work properly for me. It followed a different path when I tried it
I disagree. Both of the examples written for you work, the one from ssdesign which I tested out of interest follows a single line segment, mine follows as many as you tell it to
Avatar of GTsafas

ASKER

My apologies, I did not explain myself well in the first place after re-reading my post that is why it did not perform as expected. I found an alternate solution to my problem. Thank you for your hard work, im sure this will be valuable to someone