0
votes

I have an HTML button that I need to dynamically assign to an AS3 variable when clicked (in order to load an .mp3). I am using externalInterface.call to collect javascript variables - I am just unsure how to change these dynamically when a button is clicked.

Can anybody help me learn with some sample code?

Thanks!

2

2 Answers

2
votes

You can use ExternalInterface.addCallback to add a method to your *.swf that can be called from javascript code.

ExternalInterface.addCallback("testMethod", function(message:String) { trace(message) });

And in javascript:

document.getElementById('swf').testMethod('Hello!');
0
votes

ExternalInterface is one way, and @Andrey M has already provided some good tips on this approach.

However, if you're just passing values from HTML -> AS, consider using FlashVars, which are a more appropriate approach.