4 Replies Latest reply on May 30, 2006 11:50 AM by Newsgroup_User

    import .as file at runtime

    LSNsaltlamp
      Is there any way to import a .as file at runtime?

      When I just type:

      filename.as

      I get this error:
      **Error** C:\foldername\filename.as: Line 15: ActionScript 2.0 class scripts may only define class or interface constructs.
      };
        • 1. Re: import .as file at runtime
          Level 7
          LSNsaltlamp,

          > Is there any way to import a .as file at runtime?

          Importing is used as a convenience when referring to packaged classes.
          By typing ...

          import flash.filters.DisplacementMapFilter;

          ... at the head of my script, I can refer to the DisplacementMapFilter class
          thereafter without having to type the package (flash.filters) as a prefix
          every time.

          Including .AS files is what you're after, it sounds like. Look up the
          #include compiler directive in the ActionScript 2.0 Language Reference for
          details.


          David
          stiller (at) quip (dot) net
          Dev essays: http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: import .as file at runtime
            LSNsaltlamp Level 1
            #include is not done at runtime though. I have the same block of code in 120 files and if I want to tweak it I don’t want to have to open every file and republish them and then FTP them again. I just want to edit one .as file and FTP that single file.
            • 3. Re: import .as file at runtime
              2m Level 2
              As the player (for sake of download size) does not include a compiler, it wouldn't work this way.

              The best way to achive what you want would be to compile your classes into a swf that you load into all of your other clips.

              It seems quite complex (you would have to make sure that the swf has loaded before using it's code for example...) and debugging and testing also might be tricky, but if you really think it worth the extra miles, that how I'd try to do it.
              • 4. Re: import .as file at runtime
                Level 7
                > As the player (for sake of download size) does not include
                > a compiler, it wouldn't work this way.

                Ah, good point, 2m. I somehow glossed over the runtime part of the OP's
                question, which explains the reply I got:

                >> #include is not done at runtime though. I have the same
                >> block of code in 120 files and if I want to tweak it I don?t
                >> want to have to open every file and republish them and
                >> then FTP them again.

                Your suggestion, 2m, is right on the money.

                > The best way to achive what you want would be to compile
                > your classes into a swf that you load into all of your other
                > clips.

                Either that, or program your code to look for certain parameters
                external to the SWF -- loaded in via XML, say, or even simple text files.


                David
                stiller (at) quip (dot) net
                Dev essays: http://www.quip.net/blog/
                "Luck is the residue of good design."