OZONE Asylum
Forums
Multimedia/Animation
erm... attachMovie in class constructors?
This page's ID:
11466
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
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. So, for example.... [code] [i]// load all graphics[/i] stage = new GameStage(); [i]// move graphics around[/i] stage.moveGraphics(); [/code] My class is looking something like this... [code] class GameStage { [i]/* CONSTRUCTOR */[/i] function GameStage() { graphic_mc = attachMovie("graphic_library_name", "instance_name", 10); graphic_mc._x = 100; graphic_mc._y = 100; graphic_mc._visible = true; } private var graphic_mc:MovieClip; } [/code] And when I try it out, I'm informed that there is no such method as "attachMovie." Fine, I think -- attachMovie should be in the global scope, but apparently it doesn't exist in packaged classes. So then I try this: [code] graphic_mc = MovieClip.attachMovie(blah blah blah); [/code] And I get an error saying that the attachMovie method is not static. Okay... [code] graphic_mc = MovieClip.prototype.attachMovie(blah blah blah); [/code] No compile-time errors... but trace() shows that graphic_mc is still undefined. I've tried tossing "graphic_mc = new MovieClip();" in front of the constructor a few times, but no go. Any ideas? In Java, the correct practice is to create an object for the view (i.e. graphics, animation, user actions) and an object for the model (i.e. the "document" being worked on), then the "main code" is just a simple control loop... but if Flash doesn't want to give class objects access to library assets, then that's pretty much out the window. I might as well just make a big list of functions that get imported to the main timeline. I hope, of course, that I'm just missing something. Bwa-ha! I was in fact missing something! I'll post this just so that anyone with the same problem can find the answer here. My code should have been this: [code] graphic_mc = _root.attachMovie(args); [/code] This might be obvious to anyone with a little more experience than me, but for those with less, here you go. [url=http://faq.ozoneasylum.com/1250]Cell 1250[/url] :: [url=http://www.alanmacdougall.com]alanmacdougall.com[/url] :: [url=http://www.gurusnetwork.com/tutorials/illustrator/index.html]Illustrator tips[/url]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »