You cannot pass a data type variable (numbers or string) by reference in AS3, thus what you are trying is impossible.

I think you would have to approach this from a different angle entirely. What about having class A but also making a clone debug class A which has getters/setters for all properties and debug code at the start and end of every method. When you wanna debug your project you swap between A and the debug version of A.

At least, that’s the only way I can think of producing the sort of thing you want here.

Edit: Alternatively you can box every single data type with a wrapper class, thus allowing you to access by reference, but this would have a terrible performance impact and be bothersome to code. To do that for Int you’d basically make a class called WrapInt which only has a single “value” property to your Int value, and everytime you want to access the actual Int value you type myint.value instead of myint.

I was not aware that I could not pass data type variable by reference in AS3. I assume since you mentioned those specifically then I could pass object type variables by reference? Like TextField? If so that would suite my needs just as well.

If I were to use an object, the textField for example, is there then a way to have that variable monitored in realtime from another class if I pass a reference to the the class that is monitoring it?

Yes, object typed variables work by reference, including TextField, but you don’t have to use the native classes in Flash, making your own for your own specific purposes would be better. (don’t use an entire TextField to store a string, make your own class that stores a string).

As for monitoring in real time, no, not really. These are the ways you could try to do it at best:
1. use a timer that checks the values periodically (but it’s entirely possible the values got changed several times before the timer had the chance to react)
2. use getters and setters on the original object so it informs the debug class when a change has happened (requires you to mess with the regular class in order to debug it)
3. Use inheritance to somehow melt the debug class and the target class into one, allowing for your code to debug itself in each class (might not suit what you are trying to do at all)

Hey, do you like games? So do we — that’s what makes Kongregate the best source of free games online. We have thousands upon thousands of free online games, from both one-man indies and large studios, rated and filtered so you can play the best of the best. Read more »