0

Possible Duplicate:
calling a Flash ExternalInterface with JavaScript

I have a flash file with AS code. I want to run Javascript that will run a function the AS. For example: In the AS I have a function called "loadXML". The object that holds the SWF file called "pawel" (The ID of the object). How can I run a Javascript code that will run on "pawel" the function "loadXML"? I'm using Flash 6 with AS 3.

1
  • Check the ExternalInterface class. You will need to register that JS function by the addCallBack() method. Commented Sep 5, 2012 at 13:12

3 Answers 3

0

You should use ExternalInterface.addCallback() method. See http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html#addCallback() for details.

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

Comments

0

I suggest you check this http://www.redcodelabs.com/2012/04/calling-actionscript-method-from-javascript/ it has running sample and as3/js code.

Comments

0

I believe the goal here is to send the swf (which has compiled an external .as file) the location of an xml file somewhere on the server so the swf can compile, parse, and create something.

I've done this many times, using flash variables, which may be useful to you as well. When embedding the .swf in your webpage you can send it flash variables via js or html, or dynamically with php. Once i have my fla working perfectly with hardcoded variables (like the xml) i then add the flash variable code to the head and make a few minor adjustments to the fla – which usually breaks the fla from running "properly" within flash (because it's now dependent upon these external variables)

anyways, here's how i do my flash vars (there's other ways, worth a good google search)

import flash.net.*;

var flashVars:Object = new Object();
flashVars = this.loaderInfo.parameters;
var xmlVal;

for (var item:String in flashVars)
{
    switch (item)
    {
        case "xmlLocation" :
            xmlVal = String(flashVars[item]);
            break;

    }

}

Here's the javascript which sends the values:

<script type="text/javascript">

            //flashObj
            var flashvars = {};
                flashvars.xmlLocation = "http://google.com/myXML.xml";
            var params = {wmode:"transparent"};
            var attributes = {};
                swfobject.embedSWF("images/banner.swf", "yourSliderId", "175", "300", "9.0.0", false, flashvars, params, attributes);


        </script>

this is using SWFObject (an open API flash embedding js library) to handle the swf embed. I prefer it because if you look at the code above you can read it and understand it, the default way is really hard to read, edit and understand.

If you simply need XML and then you're done, this will work for you. If you still need to say hit the 'next' or 'previous' button using javascript, refer to this web site article, i believe this may help you out further: http://arrixlive.wordpress.com/2005/03/25/javascript-in-love-with-flash-control-swf-from-javascript/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.