0

I would like to know if it is possible to trigger a jquery function to hide something after a Mouse event in flash.

I want this to run when something is clicked in flash:

  $("#googframe").click(function() {
    $("#googframe").hide();
  });

i know how to monitor a click in AS3 but how do i get it to trigger this. By the way i am very basic so a good explanation is much appreciated.

Thanks.

DonJuma
  • 2,028
  • 13
  • 42
  • 70

3 Answers3

2

From this source: http://codingrecipes.com/calling-a-javascript-function-from-actionscript-3-flash

try in Actionscript:

import flash.external.ExternalInterface;

...

ExternalInterface.call("hideFrame");

and put your hide function in a regular function in JS:

function hideFrame() {
   $("#googframe").hide();
}
Fosco
  • 38,138
  • 7
  • 87
  • 101
1

As @Fosco said, use ExternalInterface, however the syntax should be as follows:

In AS2/AS3:

import flash.external.ExternalInterface;
ExternalInterface.call('myJsFunction'[, args...])

In Javascript:

function myJsFunction() {
    ...
}

The rest of the arguments after the first are parameters to the function that will be called (parameter list, varargs, etc).

So, as an example:

AS2/AS3:

ExternalInterface.call('addIntegers', 1, 2);

JS:

function addIntegers(a, b) {
    doSomethingWith(a + b);
    // etc.
}
mway
  • 4,334
  • 3
  • 26
  • 37
  • Two notes about this. IE7 and possibly 6 need to have the ID set on the object to make this work. You may need to futz with allowScriptAccess if the call is throwing an exception (you should always put EI calls in a try/catch). – mpdonadio Nov 08 '10 at 16:27
  • Indeed, important caveats. Thanks for adding those. Also, as another note: having to use HTML IDs and setting `allowScriptAccess` should not discourage you from using this method; this is the proper way to communicate between AS and JS. – mway Nov 08 '10 at 16:30
  • AS3 JS event listeners aside, that is. – mway Nov 08 '10 at 16:30
0

In flash call this when you need it to:

            url = "javascript:hideFlash();";
            request = new URLRequest(url);
            try
            {
                navigateToURL(request, "_top");
            }
            catch (e:Error)
            {
                trace("Error occurred!");
            }

then create you JS function called hideFlash();

Scott
  • 3,967
  • 9
  • 38
  • 56