3 Replies Latest reply on Jun 28, 2007 9:19 AM by kglad

    How do I recerence Movie Clips on the Main Timeline from inside a class?

    CPruittCCB
      Hey everyone, this might be a stupid question but I thought I'd ask cause it's making me nuts. I'm all of 2 days into AS3 (coming from not using Flash at all in YEARS) so feel free to consider me ignorant. I do have plenty of application development experience in other areas though.

      I can't seem to create a class that can reference an instance of a movie clip on my main timeline. I'd post code of what I've tried but I've gone through so many desperate edits & wild guesses that it was just garbled junk before I deleted it all.

      Basically here's how I figured Flash could work, though maybe it doesn't work this way at all.

      I'm assuming that with AS 3 being so big on being a true object oriented environment, I wouldn't need to mix my code and interface together. Preferably I'd be using the Flash authoring tools just to design my interface. Create a button... place it somewhere... give it an instance name. Roughly the equivilant of Apple's InterfaceBuilder for those of you that might be familiar with Cocoa development. I can see maybe having to put a few lines of ActionScript onto frame 1 (though really I'm hoping Flash would have a better method of kicking off the application at this point that using code tied to frames) to load my classes & such, but after that I'd like all of my code to be held in external class files.

      So maybe I've got:

      Interface.fla - My interface
      --- Button_1
      --- Button_2
      --- TextField_1
      Main.as - My main controller class using to handle all of my applications behavior
      SomeClass.as - Some helper Class
      SomeOtherClass.as - Some helper Class

      Main.as would have instructions in its initialization method to go ahead & attach events to buttons & initialize anything else that needs to happen when the application starts. From there on it would all be objects communicating back & forth. Button_1 would get clicked with would fire Main.someMethod(). Main.someMethod() would then do it's thing and set the value of TextField_1. All very clean & code is very separated from interface.

      Unfortunately I can't for the life of me figure out how AS3 classes reference each other like that. There doesn't seem to be any kind of a global 'root' or '_root' I can use to locate any movie clips on the stage. I've searched the help & the web for any kind of simple tutorial but to no avail. My job has tasked me with building a flash app for a project but I'd really rather not have a tone of ActionScript just shoved into frame 1. That just seems... ugh! (::shudder::)

      Can someone maybe point me in the right direction here? I'm really willing to do my homework but I can't seem to locate the info I need to get started. Also, is there an ActionScript IRC channel or something maybe?

      Thanks,
      Cliff