5 Replies Latest reply on Nov 12, 2009 5:42 PM by zeroskillz

    Attaching AS3 Script To Flash Movie

    benoismyname

      Hi;
      I'm getting closer. I studied 2 tutorials twice, but apparently missed an important detail. I have the following code in a file called HelloWorld.as:

       

      package
      {
         import flash.display.Sprite;
        
         public class HelloWorld extends Sprite
         {
            public function HelloWorld() {
               trace("Hello World");
            }
         }
      }

       

      I open up a new AS3 file, go to Properties and enter "HelloWorld" in the class field. Then I press ctr+enter to play the resulting swf. Nothing happens, not even a compiler error. Please advise.
      TIA,
      beno

      PS Where would I see that trace, anyway?

        • 1. Re: Attaching AS3 Script To Flash Movie
          kglad Adobe Community Professional & MVP

          your as file needs to be in the same directory as your swf and you need to type HelloWorld in the document field in the properties panel.

          • 2. Re: Attaching AS3 Script To Flash Movie
            benoismyname Level 1

            1) Open up brand new AS3 doc

            2) Ctr+F3 to get to Properties

            3) There ain't no "documents" field. Just a "class" field.

            Please advise.

            TIA,

            beno

            • 3. Re: Attaching AS3 Script To Flash Movie
              kglad Adobe Community Professional & MVP

              it should say:  "Document class:" followed by an input textfield where you would type HelloWorld.  your .as file also needs to be saved as HelloWorld.as.  case-counts in all 4 locations where you type HelloWorld.

              • 4. Re: Attaching AS3 Script To Flash Movie
                benoismyname Level 1

                I figured it out. For the record, nobody suggested, nor do I recall the tutorials I read suggested that I __save_the_file__ and *then* hit ctr+enter

                beno

                • 5. Re: Attaching AS3 Script To Flash Movie
                  zeroskillz Level 3

                   

                   

                  Yes, thats a key difference between timeline script and external script.

                  When using doc classes, any changes you make to them wont be included with the 'ctrl+enter' test until you save the external script file.

                   

                  However, if you run with it, I think you'll find it so much nicer to build alot of things that way. I rarely if ever use the timeline anymore, and most of the time my flash files are just blank docs with a document class. It really makes code re-use and repurposing much easier.

                   

                  Enjoy!

                   

                   

                  Also, your class files do not always need to be in the same folder as the .fla

                  You can put them in sub folders, but the class file needs to reflect that in it's first line.

                   

                  For instance, a standard convention for file storage is to use the revers domain name--like files for adobe.com would be in a folder com.adobe, or com/adobe/myClass.as

                   

                  the first line of your script would be:

                   

                  package com.adobe{