Reputation: 1
I'm having an issue with a "Point" type variable velocity changing without any calls to change it.
private function framecode(e:Event) {
trace(getVelocity().y);
tracks.gotoAndStop(2);
trace(getVelocity().y);
}
This code is part of a class called "tank" which extends the one that velocity is used in (my moving object class). velocity is a private point type variable and getVelocity() is a public access method. tracks is a named movieClip contained inside the one linked with tank. The event listener is ENTER_FRAME. There is no coding on the frames of tracks.
Somehow these two traces give different values (the first one being correct) and I can't figure out how the gotoAndStop() can possibly effect it (and hence how to fix it).
I've found that play() does not reproduce the bug but prevFrame() and nextFrame() do. As the variable is private this class should not even have access to it to change it.
Another strangeness is that if the event listener is changed to FRAME_CONSTRUCTED or EXIT_FRAME, there is massive lag and my movieClip randomly disappears after a few seconds.
Thank you for reading, any help would be appreciated.
Upvotes: 0
Views: 133
Reputation: 18193
Your velocity
variable is private, so one one can access that outside of the class.
However, getVelocity()
is returning a reference to your velocity
variable. Once someone has that reference, they can change the values of it's properties: getVelocity().y = 3
. So it's not impossible for this to happen.
One way to trouble shoot this is to add a trace()
statement to/set a breakpoint in getVelocity()
so you can see where it's being used.
You could do something similar w/the Point
class, but you'll have to extend it, add getter/setter methods for y
(that traces out when they are called), and modify your code to use the getter/setter. This might be worthwhile (its simple enough), and the act of modifying your code to use the getter might help you discover where the problem is.
Upvotes: 1