PDA

View Full Version : Using Trace



JapanMan
September 9th, 2008, 04:22 PM
Trace is like having the AS keep track of something without a text box or counter on the screen, right? For instance, if I have a hitTest, and I want to make sure it works, I can have code like this, right:


if (player.hitTest(enemy)) {
trace ("hit");
}

that should make the Output say "hit" if the objects run into each other, right?


P.S. I know my questions are really rudimentary. I understand the concept of all this stuff, I just always have some mundane problem when I try to do it myself :puzzled:

senocular
September 9th, 2008, 05:02 PM
That's the idea.

Skribble
September 10th, 2008, 01:56 AM
yup, you've got it right on the money!

it's very helpful for figuring out if certain functions and events are being called.

JapanMan
September 10th, 2008, 02:35 PM
then why isn't it working in the fla I'm working on:

47919


an analysis would be appreciated.

Thanks.

Smee
September 10th, 2008, 02:57 PM
It's not working because you are only running the code on the first frame. You need to put it in an onEnterFrame.


onEnterFrame = function()
{
if(_root.blob.hitTest(_root.player))
trace("hit");
}

Also, on your black dot (the custom cursor), you have this line:


updateAfterEvent(mouseMove);

The method updateAfterEvent doesn't use any arguments, so putting 'mouseMove' in there does nothing; but that's not the issue, the whole line itself does nothing. What the method does, is tell Flash to redraw the stage after the current event. The event you're using in this case, enterFrame, does that anyway. If you want the mouse to update every time it's moved, then you can use:


onClipEvent(mouseMove)
{
this._x = _root._xmouse;
this._y = _root._ymouse;

updateAfterEvent();
}

This will move the black dot to your mouse every time the mouse moves, then redraw the stage immediately. Try this code and set your frame rate to 1 to see what I mean. The mouse will be as smooth as your OS mouse, but the red circle will only move once a second.

JapanMan
September 10th, 2008, 03:01 PM
that's the most awesome thing I have ever seen. Thanks a ton.

senocular
September 10th, 2008, 03:23 PM
JapanMan, I've moved your new question to a new thread:
http://www.kirupa.com/forum/showthread.php?t=308367
since the topic no longer relates to Using Trace

If you could make new threads for new questions, that would be super ;)