In trying to learn how to create objects in ActionScript, I have had no success. One thing that I have noticed is that there seems to be a billion different ways of doing it. Even if none of them have worked for me. This is really confusing me, and I don't know which approach to try to debug.
The approach that seems to come up most often is:
function myClass() { this.val = 1; } var test = new myClass(); trace(test.val);
But this just gives me compiler errors no matter how simple I make it, and it makes no sense to me that a function could be an object. If the function is an object, where does "this" point when it is in a function in a function (that is being interpreted as an object).
Another way that seems to come up somewhat less often is:
class myClass { function myClass() { this.val = 1; } } var test = ....
This gives me compiler errors as well, and seems more formal. But I can find very little documentation comparitivley. Most guides are either very simple, or assume that you are talking about the built in objects.
A third way that came up was to create a
new Object();in a function, add all the things you wanted and return it. Seems logical. But I have read all sorts of things that mention prototypes, and it seems like an object created this way would be ill suited to be a prototype. But really I am just very confused.
I also came across something saying that Object syntax was different between AS2, and AS3, but nothing more than that.
How am I supposed to create objects? What are the best practices, and for the love of god does somebody know where I can find an in depth tutorial? (my google-fu is evidently weak)