6 Replies Latest reply on Jun 25, 2007 8:11 AM by SymTsb

    Flash CS3 and Javascript

    SymTsb Level 2
      A couple of weeks ago, I wrote in another thread about how Flash CS3 (using AS3) can directly handle javascript. I must tell you that this direct handling is limited. You cannot call custom javascript functions from html this way. If you need to call function in your html, you must still use ExternalInterface.

      Flash CS3 has a new function called navigateToURL(). navigateToURL() is part of the flash.net package and is asynchronous (does not return any kind of value).

      Let's say you want to throw a simple javascript alert message to a user. You need to first make a call to the URLRequest constructor and pass it a string value that uses javascript protocol. In the alert example, you'll be calling the string "javascript:alert('Your first AS3 javascript call');" To those familiar with HTML, this will look very very familiar. All put together, it looks something like the code below....

      This idea can be expanded on and added to custom event handlers in classes for buttons and other things in your projects. Remember though that you must call the javascript code as it appears in the javascript protocol. So to open a popup window, you'd need to use window.open( blah, blah, blah ). Personally, I still use ExternalInterface to call my Javascript functions (if I need them at all). The only reason I use navigateToURL is when the browser I'm using does not support ExternalInterface.

      Anyhow, the code for the above example is down below. If you have questions, post them here.
        • 1. Re: Flash CS3 and Javascript
          kglad Adobe Community Professional & MVP
          this looks like two steps back to getURL() which called javascript functions exactly the same way. and like getURL() to call javascript functions, should be relegated to the inactive bin in favor of the externalinterface.

          anyway, i'm more interested in your claim that URLLoader can be used to execute javascript code. how?
          • 2. Re: Flash CS3 and Javascript
            SymTsb Level 2

            my post 2+ weeks ago was adrenaline driven and premature. the example I just gave was the code I was talking about. Why I ever posted that URLLoader was capable of javascript interaction is beyond me. I know better. The purpose of my post was simply to answer questions I've been getting in my e-mail and to clarify my original post 2 weeks ago.

            As I stated, navigateToURL is meant for specific scenarios just as getURL was in AS1 and 2 which was replaced by navigateToURL in AS3. This would be more for the Linux users and the a-typical O/S users where ExternalInterface is not supported by the browsers on those operating systems. I do not condone using navigateToURL or getURL. I will always recommend external javascript files and ExternalInterface. My apologies for leading anyone on with my premature run-off of the typing finger.
            • 3. Re: Flash CS3 and Javascript
              kglad Adobe Community Professional & MVP
              ohhhhh. i hadn't considered any issues that linux users might face. and i didn't know externalinterface would fail for users of those os.
              • 4. Re: Flash CS3 and Javascript
                SymTsb Level 2
                According to Adobe, ExternalInterface only works in the following browsers....

                IE5.0+ (Windows)
                Netscape 8.0+ (Windows/MacOSX)
                Mozilla 1.7.5+ (Windows/MacOSX)
                Firefox 1.0+ (Windows/MacOSX)
                Safari 1.3+ (MacOSX)

                I have not personally tested this but I do know I've had issues with Safari in the past. Most people no longer use the deprecated browsers but since Linux/Unix aren't in the list of supported browsers, it would suffice to say navigateToURL is the only means of getting anything done with javascript on these operating systems.
                • 5. Re: Flash CS3 and Javascript
                  kglad Adobe Community Professional & MVP
                  well, anyone using browsers older than those isn't really living in the electric-age anyway.
                  • 6. Re: Flash CS3 and Javascript
                    SymTsb Level 2
                    LOL! Agreed but like I said, Linux has access to NS8, Moz1.7 and Firefox 1+ and still irregular support for ExternalInterface in the Flash Player. Just need to educate the masses since it seems we always get masses of these kinds of questions :D