|
-
Senior Member
How evil -IS- root?
I have heard MANY times that it is bad practice to use references to root. But I know I used _root many times in classes in AS2 and MovieClip(root) now in AS3.
As an example for how I use it, I have a GameUpdater class that talks to my server. Since I am polling, all it does it setup the URLLoader, URLRequest, URLVariables, and the listener events to hear when the server responds. But now my CLASS knows that the server has new data, but my maintimeline is still baffled. So my COMPLETE listener adds server updates to an array in my main timeline something like: MovieClip(mRoot).serverUpdates.push("login successful")
And it also sets appropriate properties in an object based on what was returned. Like in the login case, it would set a playerID property that comes from mySQL. My main timeline keeps an eye on that serverUpdates array and acts on anything it finds based on the content of the strings.
Is this a horrible use of root? I could use a set of functions instead of using a class and avoid root references, but I like getting that code away from my main.
My login screen is all on a separate movieclip (made in the flash api), and I have the code on that movieclip's timeline that handles what the buttons do, and the validation. It's all self-contained except that I have to make calls to that GameUpdater class variable that is on the main timeline. So my login and register buttons both reference MovieClip(root).
Is this a horriible thing to do? How can I avoid it other than putting ALL code on the main timeline? Sure I could do that, but it doesn't seem very object oriented... I could also just use parent, or parent.parent but that seems a lot more evil than root to me, since the program would break if that parent changed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|