8 Replies Latest reply on Jul 15, 2008 2:28 PM by Newsgroup_User

    Calling Javascript (k)

    Level 7
      I've done this(calling a Javascript function from Flash) before, but
      haven't done it in a while.

      I want to get this HTML code:
      <a href="JavaScript:void(0)" onclick="ChangeState('link1')">Link 1</a>

      to work in Flash. Here is where I am with it. I attached this
      ActionScript to a button in Flash. On the HTML page the flash file
      resides is the Javascript.

      on (release) {
      getURL("javascript:void(0)" and "ChangeState('link2')");
      }

      Any ideas?

      -Kirk
        • 1. Re: Calling Javascript (k)
          robdillon Most Valuable Participant
          You could use:
          on (release) {
          getURL("javascript:ChangeState('link2')");
          }

          but read through this tech note on using ExternalInterface: http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_15683
          • 2. Re: Calling Javascript (k)
            Level 7
            Your version didn't work(thanks, though).

            That technote is beyond my knowledge of ActionScript. It also appears to
            want Javascript to control Flash. I need Flash to control a Javascript
            Function.

            Any other ideas?

            -kirk




            Rob Dillon wrote:
            > You could use:
            > on (release) {
            > getURL("javascript:ChangeState('link2')");
            > }
            >
            > but read through this tech note on using ExternalInterface:
            > http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_15683
            >
            • 3. Re: Calling Javascript (k)
              Level 7
              That code should work. Any thoughts why it doesn't:

              on (release) {
              getURL("javascript:ChangeState('link2')");
              }


              -Kirk


              W. Kirk Lutz wrote:
              > Your version didn't work(thanks, though).
              >
              > That technote is beyond my knowledge of ActionScript. It also appears to
              > want Javascript to control Flash. I need Flash to control a Javascript
              > Function.
              >
              > Any other ideas?
              >
              > -kirk
              >
              >
              >
              >
              > Rob Dillon wrote:
              >> You could use:
              >> on (release) {
              >> getURL("javascript:ChangeState('link2')");
              >> }
              >>
              >> but read through this tech note on using ExternalInterface:
              >> http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_15683
              >>
              • 4. Re: Calling Javascript (k)
                Level 7
                I just tried simpler javascript that I got right from the Adobe website:

                getURL("javascript:alert('you clicked me')");


                It doesn't work either. Any thoughts? This happens in Safari and Firefox 3

                -Kirk



                W. Kirk Lutz wrote:
                > That code should work. Any thoughts why it doesn't:
                >
                > on (release) {
                > getURL("javascript:ChangeState('link2')");
                > }
                >
                >
                > -Kirk
                >
                >
                > W. Kirk Lutz wrote:
                >> Your version didn't work(thanks, though).
                >>
                >> That technote is beyond my knowledge of ActionScript. It also appears
                >> to want Javascript to control Flash. I need Flash to control a
                >> Javascript Function.
                >>
                >> Any other ideas?
                >>
                >> -kirk
                >>
                >>
                >>
                >>
                >> Rob Dillon wrote:
                >>> You could use:
                >>> on (release) {
                >>> getURL("javascript:ChangeState('link2')");
                >>> }
                >>>
                >>> but read through this tech note on using ExternalInterface:
                >>> http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_15683
                >>>
                • 5. Re: Calling Javascript (k)
                  Level 7
                  After searching the web for a while I discovered that the
                  getURL("javascript: method I'd used in the past is not secure.

                  There's a new method that I don't understand at all.

                  Has anyone successfully done any Javascript connection through Flash
                  since the April 2008 security update?

                  If so, how do you do it?

                  -Kirk





                  W. Kirk Lutz wrote:
                  > I just tried simpler javascript that I got right from the Adobe website:
                  >
                  > getURL("javascript:alert('you clicked me')");
                  >
                  >
                  > It doesn't work either. Any thoughts? This happens in Safari and Firefox 3
                  >
                  > -Kirk
                  >
                  >
                  >
                  > W. Kirk Lutz wrote:
                  >> That code should work. Any thoughts why it doesn't:
                  >>
                  >> on (release) {
                  >> getURL("javascript:ChangeState('link2')");
                  >> }
                  >>
                  >>
                  >> -Kirk
                  >>
                  >>
                  >> W. Kirk Lutz wrote:
                  >>> Your version didn't work(thanks, though).
                  >>>
                  >>> That technote is beyond my knowledge of ActionScript. It also appears
                  >>> to want Javascript to control Flash. I need Flash to control a
                  >>> Javascript Function.
                  >>>
                  >>> Any other ideas?
                  >>>
                  >>> -kirk
                  >>>
                  >>>
                  >>>
                  >>>
                  >>> Rob Dillon wrote:
                  >>>> You could use:
                  >>>> on (release) {
                  >>>> getURL("javascript:ChangeState('link2')");
                  >>>> }
                  >>>>
                  >>>> but read through this tech note on using ExternalInterface:
                  >>>> http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_15683
                  >>>>
                  • 6. Re: Calling Javascript (k)
                    robdillon Most Valuable Participant
                    Take a look at this example: http://www.ddg-designs.com/downloads/callJSfunction.zip. This is a very simple example using ExternalInterface.
                    • 7. Re: Calling Javascript (k)
                      Level 7
                      Thanks, I'll check it out.
                      I got it working the old way by changing:
                      'allowScriptAccess','sameDomain',
                      to
                      'allowScriptAccess','always',
                      in the HTML that pulls in the SWF.

                      Not sure what that does to my security. The only thing this Javascript
                      does is changes out a background image if a variable is true in Flash.

                      -Kirk


                      Rob Dillon wrote:
                      > Take a look at this example: http://www.ddg-designs.com/downloads/callJSfunction.zip. This is a very simple example using ExternalInterface.
                      • 8. Re: Calling Javascript (k)
                        Level 7
                        It's official. I am a complete and utter moron.

                        I didn't need to change a thing. I just needed to upload it off my local
                        machine with 'sameDomain' in there as it was.

                        Absolutely stupid.

                        -Kirk


                        W. Kirk Lutz wrote:
                        > Thanks, I'll check it out.
                        > I got it working the old way by changing:
                        > 'allowScriptAccess','sameDomain',
                        > to
                        > 'allowScriptAccess','always',
                        > in the HTML that pulls in the SWF.
                        >
                        > Not sure what that does to my security. The only thing this Javascript
                        > does is changes out a background image if a variable is true in Flash.
                        >
                        > -Kirk
                        >
                        >
                        > Rob Dillon wrote:
                        >> Take a look at this example:
                        >> http://www.ddg-designs.com/downloads/callJSfunction.zip. This is a
                        >> very simple example using ExternalInterface.