Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
Please ask this in a relevant stack, this has nothing to do with WordPress. –  Wyck Aug 14 '11 at 14:45
    
see your point Wyck, started off as a WPeC, Wordpress question but for clarity stripped it back and see your point. Is there a way of transferring the question to another stack (can't see a Flash stackexchange)? Thanks –  Dean Rowe Aug 14 '11 at 14:53
    
evolved from this unanswered post: wordpress.stackexchange.com/questions/25778/… –  Dean Rowe Aug 14 '11 at 14:58
    
Maybe a mod will move it, but you will probably get more flash/jquery experts on the main stackoverflow.com –  Wyck Aug 14 '11 at 15:01

2 Answers 2

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

import flash.external.ExternalInterface;
if (ExternalInterface.available) ExternalInterface.call("myJavascriptFunction", param1, param2);
share|improve this answer
    
Hi Milo, no joy with that code - and don't know how to start to debug. code used: if (ExternalInterface.available) ExternalInterface.call("helloWorld"); –  Dean Rowe Aug 14 '11 at 15:25
    
I've posted problem on some dedicated flash forums, will post answer once found. Thanks for help –  Dean Rowe Aug 14 '11 at 17:34
up vote 0 down vote accepted

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">

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.