Call a Simple JQuery from within Flash

This is hopefully really simple for someone but I'm a newbie and trying to learn how to connect to JQuery's on my site from an embedded Flash swf. I'm attempting to do a simple example first to test the connection between Flash and JQuery...

I've embedded an swf onto my page. When I click my button in Flash I'd like it to connect to a JQuery function that produces a popup alert saying "hello world!"

Here's my JQuery function (I need to name the function):

function helloWorld() {
       alert('Hello World');
 }

I have an eventlistener (which I tested and works) on my button within Flash which tries to call the following:

function AddToBasket(event:MouseEvent):void{
var alert:URLRequest = new URLRequest("javascript:helloWorld();");
navigateToURL(alert);
}

When I 'inspect element' in Chrome I can see the JQuery is there, but when I click my button no popup alert appears. I'm misunderstanding something pretty basic, any help would be appreciated!!!

My Flash SWF is added to my Wordpress page using Kimili Flash Embed, which I've added to my WP page like this:

[kml_flashembed movie="http://www.example.co.uk/upload/ImageUploader.swf" allowscriptaccess="samedomain" height="500" width="728" /]

The following AS3 does produce the popup, but the whole point of the exercise is calling a JQuery outside of Flash:

function AddToBasket(event:MouseEvent):void{
var alert:URLRequest = new URLRequest("javascript:alert('Hello World!')"); //"javascript:helloWorld();"
navigateToURL(alert, "_self");
}

Thanks guys

Dean

Topic flash jquery Wordpress

Category Web


it was the kimili embed causing problems, embedded in different way and now working. Thanks for all the help!.

final code:

      <script type="text/javascript">
 function helloWorld() {
       alert('Hello World function yeah');
 }
</script>

and AS3:

 function AddToBasket(event:MouseEvent):void{
ExternalInterface.call("helloWorld");
}

and embedded swf code:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="macromedialinkremoved/pub/shockwave/cabs/flash/swflash.cab" width="728" height="500" id="ImageUploader">


Use AS3's ExternalInterface to call JavaScript functions from within Flash applications.

import flash.external.ExternalInterface;
if (ExternalInterface.available) ExternalInterface.call("myJavascriptFunction", param1, param2);

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.