5 Replies Latest reply on Oct 5, 2007 8:46 AM by kglad

    including external as files

    ToonMariner
      Hi,

      I have pretty much near the end of my first flash project - quite happy with my media player.

      Only issue I have is with the following if statement which is bothering me.


      if (
      file.substr(file.length - 3,3) == 'mp3'
      )
      {
      #include "video.as"
      }
      else
      {
      #include "video.as"
      }

      If i have teh above code in the, media player fails hwoever if I just have one of the includes in it works fine.

      Can any one suggest whats going on?

      I pass the 'file' parameter via flash vars in the object tag pf html (end in teh embed tag too) and it is simply an .flv or .mp3 that gets passed there...

      Many thanks in advance.
        • 1. Re: including external as files
          kglad Adobe Community Professional & MVP
          is this a trick question? is there some point to using that code instead of just using:

          #include "video.as"
          • 2. Re: including external as files
            ToonMariner Level 1
            oops - my bad

            if (
            file.substr(file.length - 3,3) == 'mp3'
            )
            {
            #include "audio.as"
            }
            else
            {
            #include "video.as"
            }

            if that code is in the file then the whole thing fails - just include one of them and its fine. Am I correct in thinking that the if statement would only include one of the as files or is there some idiosyncrosy where they would both be included regardless (much like the require in php3!)
            • 3. Re: including external as files
              kglad Adobe Community Professional & MVP
              there's no problem with your code. but you are making an error.

              my guess is that you're defining file dynamically (as an mp3 file reference) and video.as is the code that's compiled, NOT audio.as

              that's because you can't define file during run-time and have it affect that if-statement. file must be assigned during compile-time when your as files are included for compilation. in other words, #include statements are compiled into your swf when you publish your swf, NOT during run-time.
              • 4. Re: including external as files
                ToonMariner Level 1
                You are correct I reference a file dynamically... it is either mp3 or flv

                So is my logic at fault?
                I was of the impression that the if statement above would include audio.as if the file ended in mp3 and video.as if it didn't...
                • 5. Re: including external as files
                  kglad Adobe Community Professional & MVP
                  again, there is no problem with your code. the problem is you don't understand the #include directive.

                  when #include is encountered during compile-time (ie, when you publish your swf), flash includes the code in your as file in the published swf. once the swf is published, more code cannot be added to it so encountering an #include statement during run-time is irrelevant.