Actionscript 3.0 X Y coordinates

16 posts

Flag Post

Hi,

Does anybody know a directive for displaying x and y coordinates on the stage or in the output window?

 
Flag Post
trace(thing.x+", "+thing.y) ?
 
Flag Post

Ok thanks. So what would the word be for tracing the cursor coordinates?

 
Flag Post
trace(mouse.x + ", " + mouse.y);
 
Flag Post

You could put it inside a text field

Inside an onMouseMove function, place this:

myTextField.text = mouse.x + ", " + mouse.y
 
Flag Post

Thanks guys.

 
Flag Post
Originally posted by Elyzius:
trace(mouse.x + ", " + mouse.y);

Just a minor thing, but the quotes, plus signs, etc aren’t necessary with trace statements. This will suffice as well:

trace(mouse.x, mouse.y);
 
Flag Post
Originally posted by Aesica:
Originally posted by Elyzius:
trace(mouse.x + ", " + mouse.y);

Just a minor thing, but the quotes, plus signs, etc aren’t necessary with trace statements. This will suffice as well:

trace(mouse.x, mouse.y);

Yes they are, unless you want this:

15.752.25

As your output.

(Is that 15.75 and 2.25 or 15.7 and 52.25?)

 
Flag Post

It gives you a courtesy space.

trace("hi", "guise"); // hi guise
trace(mouse.x, mouse.y); // 15.75 2.25
 
Flag Post

Never used it, largely because I like formatting my output in the way I want it formatted.

trace("ThatOneVar: " + someVar);
trace("SomeVarProperties: " + otherThing.prop + ", " otherThing.dohicky);

etc.

 
Flag Post

If that’s the case, I’m pretty sure my trace statements would make you want to punch a baby. :o

 
Flag Post
Originally posted by Aesica:

If that’s the case, I’m pretty sure my trace statements would make you want to punch a baby. :o

Almost certainly.

I’ll take whole if-statements and put +""+ around the operators (e.g. trace(someX + “>” + value);) to insure that an if statement is being correctly evaluated.

 
Flag Post

What I use to trace:

package{
    import org.flashdevelop.utils.FlashConnect;
    import flash.utils.getQualifiedClassName;
    import flash.system.Capabilities;
    
	public class Log{
		private static var
			b:Boolean;
			
		public function Log():void{throw "derp.";}

		public static function it(S:*="",...args):void{	
			var 
				i:int;
			if(!Capabilities.isDebugger){
				var 
					t:String=String(S);
				if(args)
					for(;i<args.length;++i)
						t=t+"\t"+args[i];
				FlashConnect.trace(((b=!b)?"1: ":"3: ")+t);
				return;
			}
			var 
				s:String=new Error().getStackTrace(),
				ii:int=s.indexOf("()",s.indexOf("()")+1);
			i=s.indexOf("at ",s.indexOf("at ")+1)+3;
			s=s.substring(i,ii);
			var 
				d:int=s.indexOf("/"),
				ss:String=s.substr(d+1);
			s=s.substring(0,d);
			var 
				r:String="["+(s?s:ss)+"]  ("+ss+")  : ";
			s=String(S);
			if(args)
				for(i=0;i<args.length;++i)
					s=s+"\t"+args[i];
			FlashConnect.trace(((b=!b)?"1: ":"3: ")+r+s);
		}
	
	}
}
 
Flag Post
Originally posted by Elyzius:
trace(mouse.x + ", " + mouse.y);

Is it not mouseX, mouseY?

 
Flag Post

You’re right. I stand corrected.

 
Flag Post

In a way, you’re both right:

var mouse:Sprite = new sprite();
mouse.addChild(new Assets.Rodent());
mouse.x = cheese.x - mouse.width;
mouse.y = cheese.y;