0

UPDATE: ANSWERED!

June 7th - I found the answer and accepted below. I am keeping this code so others can see what issues I had and maybe they can learn what works and what didn't.


OLD POST:

I just figured out how to get as3 to call a jQuery function: as3 calling jQuery function

But now I want to know how jQuery can call an as3 function. Any thoughts?

UPDATE: Not fixed yet - WHAT AM I MISSING?

Here is the code in my jQuery

 function BeGone()
  {
      var flash = $("#BeauFullScreen");
      flash.myFunction();
       $("#Content").show();


  }

Here is my code in my as3

import flash.external.*;
function callMe() 
{ 

    var bParts = Beau.content as MovieClip;
    bParts.Beau.BeauBody.LeftWing.gotoAndStop(1);
    bParts.Beau.BeauBody.RightWing.gotoAndStop(1);
    bParts.alpha = .5;

} 
ExternalInterface.call("myFunction", callMe);

My Embedded Flash Object code:

<div id="flashContentABOVE">
            <object classid="33" width="100%" height="100%" id="BeauFullScreen" align="middle">
                <param name="movie" value="BeauFullScreen.swf" />
                <param name="quality" value="best" />
                <param name="bgcolor" value="#ffffff" />
                <param name="play" value="true" />
                <param name="loop" value="true" />
                <param name="wmode" value="transparent" />
                <param name="scale" value="noscale" />
                <param name="menu" value="true" />
                <param name="devicefont" value="false" />
                <param name="salign" value="" />
                <param name="allowScriptAccess" value="sameDomain" />
                <!--[if !IE]>-->
                <object type="application/x-shockwave-flash" data="BeauFullScreen.swf" width="100%" height="100%" id="BeauFullScreen">
                    <param name="movie" value="Jesus.swf" />
                    <param name="quality" value="best" />
                    <param name="bgcolor" value="#ffffff" />
                    <param name="play" value="true" />
                    <param name="loop" value="true" />
                    <param name="wmode" value="transparent" />
                    <param name="scale" value="noscale" />
                    <param name="menu" value="true" />
                    <param name="devicefont" value="false" />
                    <param name="salign" value="" />
                    <param name="allowScriptAccess" value="sameDomain" />
                <!--<![endif]-->
                    <a href="http://www.adobe.com/go/getflash">
                        <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                    </a>
                <!--[if !IE]>-->
                </object>
                <!--<![endif]-->
            </object>
        </div>
1
  • JS or jQuery work the same when about calling an as3 function. Check this link for back and forth method calls redcodelabs.com/2012/04/… Commented Jun 7, 2012 at 8:12

4 Answers 4

1

One simple (non-jQuery) solution is to set it up within Flash using externalInterface.addCallback. Then you can call it from anywhere within your jQuery/Javascript. Just keep in mind that you need to specify the name and ID of the flash object in order for Javascript to identify it.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh man I really need some help. Can you TeamViewer.com with me? :)
1

First, in JS/jQuery code you need a small update:

function BeGone()
  {
      var flash = $("#BeauFullScreen").eq(0); //change here
      flash.myFunction();
       $("#Content").show();
  }

Then in Asctionscript:

import flash.external.*;
function callMe() 
{ 

    var bParts = Beau.content as MovieClip;
    bParts.Beau.BeauBody.LeftWing.gotoAndStop(1);
    bParts.Beau.BeauBody.RightWing.gotoAndStop(1);
    bParts.alpha = .5;

} 
ExternalInterface.addCallback("myFunction", callMe); //change here

2 Comments

Oh man I was so excited I thought this was it. Nope. There must be something little I am forgetting. Thank you so much for you help. Are you free today to do a teamviwer.com with me so you can see my script and code and screen. I really need to figure this out asap but its not working.
is function BeGone called after the DOM has been constructed / loaded? Try console.log(flash); to see if your selector is working properly.
1

THE ANSWER THAT WORKED FOR ME!

I had to add 3 important elements!

1) Below is the line of code I needed for jQuery to communicate with as3 and call the function inside as3.

function BeGone()
{
$("#BeauFullScreen").get(0).myFunction(); /// THIS LINE WAS THE KEY!    
}

2) I also needed to add the swfObject javascript:

<script> src="swfObject.js"></script>

3)** Finally I had to embed my SWF with JavaScript rather than the way Dreamweaver inserts the code as seen above in my question. Embedded JavaScript code below.

    <script>
    var flashvars = {
    };
    var params = {
        menu: "false",
        scale: "noScale",
        wmode: "transparent", // added this to no avail
        allowFullscreen: "true",
        allowScriptAccess: "always",
        bgcolor: "",

    };
    var attributes = {
        id:"BeauFullScreen"
    };
    swfobject.embedSWF(
        "BeauFullScreen.swf", 
        "flashContent", "100%", "100%", "10.0.0", 
        "expressInstall.swf", 
        flashvars, params, attributes);
</script>

I hope this helps someone. Thank you everyone for all your awesome efforts!

Comments

1

Here is a nice little plugin to do so with a little description on how to use it

http://www.davecomeau.net/blog/56/jQuery+Plugin%3A+externalInterface

I hope it helps!

Here is a more detailed answer:

* In your html page *

1 Create your div which contains the flash with id "flashMovie"

2 Create a button for testing purposes Click To Call External Interface (with success callback)

3 Do not forget to add the required references to jquery, query.externalinterface.js, swfobject (should be replaced by your sw object)

<script type="text/javascript" src="/javascript/jquery/jquery-1.3.2.js"></script>
<script type="text/javascript" src="/javascript/jquery/jquery.externalinterface.js"></script>
<script type="text/javascript" src="/javascript/swfobject/swfobject.js"></script>

4 add the JavaScript function that will call the flash object once the button is clicked

<script type="text/javascript">

swfobject.embedSWF('/flash/externalInterfaceExample.swf', 'flashMovie', '238', '155', '10.0.0');

function interfaceTest()
{
    $('#flashMovie').externalInterface({
        method:'flashMethodToCall',   // this method has to be already defined in your flash object
        args:'some arguments',
        success: function(response)
        {
            alert('flash says: ' + response);
        },
        error: function(error)
        {
            alert('error: ' + error);
        }
    });
}
 </script>

* in your action script **

import flash.external.*;

function someMethod() 
{ 
// Here goes your code
} 
ExternalInterface.addCallback("flashMethodToCall", someMethod); 

4 Comments

I think I am close with this line but I don't know how to add my function in the place of flashMethodToCall. $('#flashContentABOVE').externalInterface({method:'flashMethodToCall'});
Did you check the demo source? It is on the same page. The main point here is to give your flash object an id. Then use it to call the method you dre interested in.
Oh man I can't figure it out. I got the id but what is the jQuery code I use to call the id and the function in that flash container?
I have put a more detailed answer. I hope things are not much clearer from your side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.