MisterMister
01-19-2005, 07:59 PM
OK, I'm pretty new to actionscript, but this problem has me perplexed.
Here's some sample code to illustrate my question.
main();
function main() {
var test = new SpiffyObject();
trace(test.test);
}
SpiffyObject = function (){
this.test = 1234;
}
It's traces undefined because it doesn't instatiate the object "test". But if I move the constructor for SpiffyObject up above the main() call then it works fine. So I'm guessing that Actionscript lets you call a function with code below, but not instatiate an object with code below.
I've just never encountered that before. Am I doing something wrong, or is that just the way Actionscript does it's thing. I know I can use an #include something.as, and I've been doing that, but this is driving my crazy, I just want to make sure I have this right in my head. I can't find it in any of my Actionscript books.
So to sumise, do classes have to be defined above a new object call? Unlike function calls?
Thanks,
Mark
Here's some sample code to illustrate my question.
main();
function main() {
var test = new SpiffyObject();
trace(test.test);
}
SpiffyObject = function (){
this.test = 1234;
}
It's traces undefined because it doesn't instatiate the object "test". But if I move the constructor for SpiffyObject up above the main() call then it works fine. So I'm guessing that Actionscript lets you call a function with code below, but not instatiate an object with code below.
I've just never encountered that before. Am I doing something wrong, or is that just the way Actionscript does it's thing. I know I can use an #include something.as, and I've been doing that, but this is driving my crazy, I just want to make sure I have this right in my head. I can't find it in any of my Actionscript books.
So to sumise, do classes have to be defined above a new object call? Unlike function calls?
Thanks,
Mark