Topic: erm... attachMovie in class constructors? |
|
---|---|
Author | Thread |
Paranoid (IV) Inmate From: Milwaukee |
posted 10-19-2003 03:05
So, I've got this class, which is supposed to load, place, and control all the graphics in the game. Let's call it "GameStage." I'm trying to get its constructor to summon up and place a bunch of MovieClip elements, then there are a bunch of public instance methods that move the elements around. code: [i]// load all graphics[/i]
code: class GameStage
code: graphic_mc = MovieClip.attachMovie(blah blah blah);
code: graphic_mc = MovieClip.prototype.attachMovie(blah blah blah);
code: graphic_mc = _root.attachMovie(args);
|
Maniac (V) Inmate From: Boston, MA, USA |
posted 10-19-2003 19:36
PT - just for the sake of clarity in other posts - are you currently using MX 2004? If no, there are some big problems in this code. (MX doesn't have a "class" keyword, and isn't strongly typed to give two examples of what I mean.) code: function GameStage()
code: function GameStage()
code: _global.mainTL = this;
|
Paranoid (IV) Inmate From: Milwaukee |
posted 10-19-2003 23:36
Hey, quite handy -- I didn't know about with to set a bunch of properties (or, I assume, access a bunch of methods) at once. And yes, I'm using MX 2004 for this project (or else I'd still be frustrated, because it still wouldn't work!) The strict typing is unnecessary for this project, but I'm trying to teach myself good habits. And making a global reference to _root is an excellent idea, especially since I'm going to be doing some nesting. Thanks for the tip. |
Paranoid (IV) Inmate From: Milwaukee |
posted 10-20-2003 03:07
Well, back to scope problems -- and this is MX-relevant, so I hope you can give me a hand. It's very simple: I have a generic object acting as a keyboard handler, and within the onKeyDown inline function I want to refer to an object on the same level as the handler object. An example should make it more clear: code: var test = 12;
|
Maniac (V) Inmate From: Boston, MA, USA |
posted 10-20-2003 03:45
I copied your code, pasted it unmodified into a new Flash MX movie, and the output window displayed: quote:
quote:
code: trace("Key pressed.");
quote:
|
Paranoid (IV) Inmate From: Milwaukee |
posted 10-20-2003 04:09
(sigh) I guess it's something 2004-related after all. I should probably just code to MX practices until 2004 has been out long enough to have a reasonable penetration -- it'll make it more likely that my problems can be resolved with simple Googling. code: class TheClass
|
Maniac (V) Inmate From: Boston, MA, USA |
posted 10-20-2003 04:54
Beyond me tonight. |
Paranoid (IV) Inmate From: Milwaukee |
posted 10-20-2003 23:56
Well, I found a solution! code: [i]// in the class constructor...[/i]
|
Paranoid (IV) Inmate From: Milwaukee |
posted 10-30-2003 16:01
For anyone who might be using this thread for help, I feel like mentioning something I only found out after some troubleshooting... to register a new variable as a property of an object, you can't use with(). For example, this code... code: with (existing_object)
code: existing_object.new_var = 0;
code: var existing_object.new_var;
|
Maniac (V) Inmate From: Boston, MA, USA |
posted 10-31-2003 17:58
I had never tried to use "with" to declare a new variable/property either, so I didn't know it couldn't be done. |
Paranoid (IV) Inmate From: Milwaukee |
posted 11-02-2003 19:59
(sigh) Okay, I glanced at the article without reading it, and then I did some programming... how do you like that, I can't access private variables from inside a with() statement! Looks like I'd better read the article ASAP... thanks for the pointer, Steve. quote:
|