This content has been marked as final. Show 7 replies
i don't think this is great programming.
first, nothing is going to happen when the applyNewColour() method is called unless myColour is explicitly defined.
second, the use of "this" in applyNewColour serves no purpose except to make the code more difficult to understand. better coding would be:
many thanks for your post.
regarding the programming, I think the study material is leading me, in a stepwise manner, to good programming practises by showing, in part, not so good practises; the study material makes reference to the function applyNewColour as 'cumbersome'.
I do understand that the function myColour needs to be explicitly defined for anything meaningful to happen, however thank you for confirming that.
What the study material has bought to a head for me is that I have not fully digested and understood how the keyword 'this' is used or when it is appropriate to use it or how it is correctly used.
Perhaps it's because I have not sufficently mastered other aspects and principles of actionscript that I have a block with the keyword 'this'?
If you are able to offer any insight on the 'this' item it will be gratefully received with thanks, if not, many thanks for getting me thus far with my efforts.
Either way I shall continue with my study material in the hope that the proverbial penny will eventually drop for me.
hey, i'm very comfortable with actionscript and i can run into problems with "scope" in class files. that's why i like to explicitly assign a variable to be a class instance. eg, _vogon.
it's very easy to misuse "this" in a class. all you need is a data handler (like a loadvars instance or a moviecliploader instance) or a setInterval() loop and "this" no longer refers to a class instance.
when in doubt, it's very handy to use
// and sometimes
this(this instanceof Vogon); // or whatever class if trace(this) results in an object
thank you for your feedback kglad,
i think your post has kinda reassured me that I'm not mentally struggling with a 'simple' issue here yet also kind of unsettled me in that i'm now wondering if i'll ever get a handle on it - if you know what i mean. i suspect, for me, it'll be one of those aspects of flash that will have an enduring elusive quality to it - and just holding that thought will help me to perservere with it.
anyway, what i do pick up from your last post, and shall try to observe and practise in my coding, is to explicitly assign a variable to be a class instance (as appropriate) eg, _vogon so as to better define variable 'scope' within class files which, i believe, will get me another step closer to best practice.
this post, and your contributions today, has certainly helped my actionscript study efforts and, while not definitively answering the query, allows me to broaden my understanding a little further and move forward.
again, thank you.
to more explicitly answer your question: "this" refers to a Vogon instance. when the applyNewColour() method is applied to that instance, its color will be changed (if myColour is appropriately defined).
sorted! - well, at least for now.