2
votes

I am very new in FDT, I want to pass javascript variable value to FDT code. I have no idea how to do it.

HTML Code:

<a id="player" href="javascript:void(0)" data-id="02">ABCD</a>

Javascript Code:

$('.list a').click(function(){ 
  var id = $(this).data("id");
}

In FDT, with id 02 there is SWF file link.

Or is there any another way to do it? Please help me.

Thanks in adcance.

2

2 Answers

2
votes

you need to use ExternalInterface in swf, to catch function calls from javascript

import flash.external.ExternalInterface;

if (ExternalInterface.available){
    ExternalInterface.addCallback("changeText", changeTheText); 
}

function changeTheText(t:String):void {
    txtText.text = t;
}

JavaScript code

var flashObj = document.getElementById('flashObject');
<a href="#" onClick="flashObj.changeText('it works!');">Click me!</a>

Example here: http://www.hardcode.nl/archives_155/article_334-call-javascript-function-from-as3-and-viceversa.htm

Search google for "javascript/as3 bridge"

0
votes

In addition to what @bFunc mentioned, I might advise doing your onclick event outside of the anchor tag, if possible. I find it best to target your elements that receive action via JS rather than embedded in the HTML code. This way, you can wrap the flashObj.changeText call in a try/catch to avoid JS errors (which may happen), and handle the error appropriately (i.e. if your SWF isn't available or loaded, like when a user doesn't have Flash Player installed).

For example:

HTML Code:

<a id="flash_bridge_link" href="#" onclick="javascript:void(0)">Click Me</a>

Javascript:

var flashLink = document.getElementById("flash_bridge_link");
var flashObj = document.getElementById("flashObject");
flashLink.onclick = function () {
    try {
        flashObj.changeText("it works!");
    } catch (error) {
        // Handle error as needed.
    }
}

Hope it helps!