11 Replies Latest reply on Sep 7, 2006 5:54 AM by beko75

    Action Script (.as) external use

    beko75
      Hello there,

      I just learned how to use external .as which will load in a movie.
      Well, I really was happy when I found out how to call the external .as, but every happiness is followed with sadness.
      When I make changes in my .as file, they do not affect the .swf file (i.e. there are made no changes in the .swf file) unless the files is published anew.
      I wonder why did Macromedia came to such idea when this function is not implemental?
      However, does anyone know any other option where I can make the changes from the external .as file and take effect in the .swf file?
      I would highly appreciate an answer to my puzzle.

      Advance thanks,
      Beko
        • 1. Re: Action Script (.as) external use
          aniebel Level 2
          This may be a silly question, but did you make sure to save your .as file before trying to test your swf? Changes in the .as file will affect the .swf but if it's not, there could be many reasons why it isn't. Can you post the code from both the .as and the .fla and maybe someone will have a better idea of why it isn't working for you?
          • 2. Re: Action Script (.as) external use
            Level 7
            > I just learned how to use external .as which will load in a movie.

            No you didn't. You have just misunderstood the whole process

            .as files are NOT read by SWF files .. they have NO impact on a SWF file
            once it is published. You should NOT upload your .as file to a server with
            your SWF file (or you will be giving away your code.

            > However, does anyone know any other option where I can make the changes
            > from
            > the external .as file and take effect in the .SWF file?

            That is not possible

            What you CAN do is compile you .as into a SWF file and then load the SWF
            file and access the script within it as you would script in any other level
            or clip.
            --
            Jeckyl


            • 3. Re: Action Script (.as) external use
              Level 7
              > Changes in the .as file will affect the .swf

              No it won't .. where do you people get these ideas from?

              .as has NO EFFECT WHATSOEVER once the .SWF is published.

              .as files are read by Flash itself and combined with the script in your FLA
              as Flash publishes the SWF .. the .as content is already part of the SWF
              when it is published.
              --
              Jeckyl


              • 4. Re: Action Script (.as) external use
                beko75 Level 1
                Jeckyl, are you now convinced that the .swf file isn't updating the .as modifications?
                Download the files as zip from the following URL:

                http://www.ppsa.de/bekim/flash/Countdowntimer.zip

                Have a look at the flash files itself . It is a countdown timer.
                Note: When opening the .as file, there is a code where you can modify the timer;
                euro = new Date(2007, 04,-115, -06, -12, 00);

                Have a look at the .swf file first and remember the timer. Open the .as file and make the changes at the above code but do not touch anything at "04" number since the code is messing somehow. Try to make changes either at -115, -06, or -12.
                When I make these changes withing the .fla file itself, the changes take effect of course after publishing the movie.
                What is the puropose of the external .as file then according to you if it as not able to make the changes in a swf file?

                Beko
                • 5. Re: Action Script (.as) external use
                  Rothrock Level 5
                  Jeckyl knows his stuff. And he is correct. Changes in the .as file should only be updated when you compile/make a new swf file from a fla that references the as file. That is the only time this should happen. It is the same with #include files as well – they are only #included at compile/publish time not at runtime.

                  I think the issue here is an incomplete understanding of what happens when you publish/create a swf. All the nice readable actionscript code is converted into bytecode (not really readable to you and me, but totally readable to the Flash player – and as best I can tell to Jeckyl too! :) )

                  So a nice little as file is not something that the Flash plug-in player will have a clue what to do with. The as file needs to be turned into bytecode and that means a swf – either an external one as Jeckyl suggested or somehow melded into another file using #include or class or whatever other way you can.

                  Personally I don't use these external files, because as you are discovering, their use is less than you would want. The purpose (as best I can tell) from the olden days was to make Flash more similar to other languages where external class declarations were pretty much the way to go. So if you had some code that you would use over and over again you could easily maintain it in one location and reference it in many other files.

                  That is what they are for. Wishing they worked differently will not make it so.

                  I haven't checked out your project, but perhaps if you just need to update the date or some such you can use an external XML file to load the needed info? That could be a fairly easy solution to your problem. (And before you ask, "No, you can't store actionscript in an xml file and have the plug-in "interpret it for you.")
                  • 6. Re: Action Script (.as) external use
                    aniebel Level 2
                    I understood him to say that when he PUBLISHED a new SWF it was not affecting it. Not that the existing swf would be affected. I guess I assumed too much when I assumed this person was talking about testing his or her movie. Sorry for not reading the post correctly but sometimes... especially when a post is written vaguely.. one has to try to read between the lines.

                    Beko, please make sure you republish your file and save your .as prior to doing so.
                    • 7. Re: Action Script (.as) external use
                      Level 7
                      > Jeckyl, are you now convinced that the .swf file isn't updating the .as
                      > modifications?

                      Absolutely .. you obviosuly don't know how .as file work

                      > What is the puropose of the external .as file then according to you if it
                      > as
                      > not able to make the changes in a swf file?

                      It is to let you make your script external to the FLA file. Read the docs.

                      >>
                      Includes the contents of the specified file, as if the commands in the file
                      are part of the calling script. The #include directive is invoked at compile
                      time. Therefore, if you make any changes to an external file, you must save
                      the file and recompile any FLA files that use it.
                      >>
                      --
                      Jeckyl


                      • 8. Re: Action Script (.as) external use
                        beko75 Level 1
                        Warm greetings to everyone,

                        First of all, I would greatly like to appreciate all your efforts posted in reference to my question although my puzzle is unsolvable.

                        Aniebel,
                        I think I am fairly aware about what I have written. I never intended to write as “a new .swf file”. “Anew” is the synonym of “again” to the best of my knowledge. Whereas “a new” maintains its meaning as “an another one”… Ok. Let’s cut the long story short.

                        So, based on my preliminary clarification, I asserted that the .swf file applies the changes only when published “again” from the .fla source file after the modifications are already done in .as file. I didn’t mean to publish “a new” file.
                        If anyone downloads my files from the above given URL ( http://www.ppsa.de/bekim/flash/Countdowntimer.zip ) and has any sort of solution modifying the script externally, I would appreciate it to the uppermost. If there is no answer on it, I wish you pleasant and peaceful times in your lifetime.

                        Many thanks,
                        Beko
                        • 9. Re: Action Script (.as) external use
                          Rothrock Level 5
                          There is no way to externally modify the script. Script MUST be published in order for the player to use it.

                          I don't download strange files and poke around, but if you can explain what you are trying to achieve with the modifications then perhaps the external text or XML file will work.
                          • 10. Re: Action Script (.as) external use
                            Level 7
                            beko75 wrote:
                            > Jeckyl, are you now convinced that the .swf file isn't updating the .as
                            > modifications?
                            > Download the files as zip from the following URL:
                            >
                            > http://www.ppsa.de/bekim/flash/Countdowntimer.zip
                            >
                            > Have a look at the flash files itself . It is a countdown timer.
                            > Note: When opening the .as file, there is a code where you can modify the
                            > timer;
                            > euro = new Date(2007, 04,-115, -06, -12, 00);
                            >
                            > Have a look at the .swf file first and remember the timer. Open the .as file
                            > and make the changes at the above code but do not touch anything at "04" number
                            > since the code is messing somehow. Try to make changes either at -115, -06, or
                            > -12.
                            > When I make these changes withing the .fla file itself, the changes take
                            > effect of course after publishing the movie.
                            > What is the puropose of the external .as file then according to you if it as
                            > not able to make the changes in a swf file?
                            >
                            > Beko
                            >


                            Aniebel is right. There is nothing wrong with the .AS file. I
                            downloaded the ZIP and took a look. I opened the .AS file, made changes
                            , saved my changes, opened the FLA, published the movie and the newly
                            created SWF was in fact updated with the changes I made. This is the
                            proper way external .AS files work. AS files are no longer used once
                            the SWF is created as they are compiled into the SWF. You deploy the
                            SWF by itself. It's not like JavaScript where you add a script tag to
                            an HTML page and link to an external JS file that you may update at any
                            time and the HTML page uses the updates.

                            To answer your question, the usefulness of .AS files are two fold:
                            1. Maintain libraries of reusable code that you can plug into multiple
                            projects with an #include statement without copying-n-pasting your code
                            everywhere you need it. By "#including" your library you maintain one
                            instance of your code which is easier to make changes to without having
                            to hunt down all of the locations you may have used the same code. For
                            example, you might create some prototypes to enhance the MovieClip class
                            and would like your new methods to be used in every project you do.

                            2. Custom classes require external .AS. If you create a custom class,
                            you must put the class in an file with the same name as the class and
                            place that file in a directory structure that matches the namespaces you
                            use. For example a class com.jor.Example would be a file named
                            Example.as in a folder "jor" inside a folder "com".

                            Both methods are a good way to separate the presentation layer from the
                            business logic and are considered 'best practice' in most situations.

                            In your example, you're not really obtaining a benefit of using an
                            external file which is probably why you are having difficulties with
                            seeing their usefulness. My recommendation is to either forget the AS
                            files and put the code inside the FLA or modify the code a little to be
                            more generalized for other applications where you might also import this
                            code. Making a countdown class with public methods might be very useful
                            to other projects.

                            Not that it will matter much in this application but I thought it worth
                            mentioning, since accessing variables is faster than performing math
                            calculations one way to simplify your math a bit and reduce your CPU
                            usage would be to reuse the calculations already done. For example:

                            FROM:
                            days = (euro-now)/1000/60/60/24;
                            hours = (euro-now)/1000/60/60-(24*daysRound);
                            minutes = (euro-now)/1000/60-(24*60*daysRound)-(60*hoursRound);
                            seconds =
                            (euro-now)/1000-(24*60*60*daysRound)-(60*60*hoursRound)-(60*minutesRound);

                            TO:
                            days = (euro-now)/1000/60/60/24;
                            hours = days%1*24;
                            minutes = hours%1*60;
                            seconds = minutes%1*60;

                            Just an idea,

                            James O'Reilly
                            www.jamesor.com
                            • 11. Re: Action Script (.as) external use
                              beko75 Level 1
                              Thanks for your efforts JOR. That's very kind of you. I will try to use your ida.

                              Sincerely yours,
                              Beko