I have a flash 开发者_StackOverflow社区music player that I would like to accept a parameter via a button click on a website. I'm thinking I could do this with javascript but not sure how.
Does anybody have any sample code for both the javascript and what I would use to request the variable inside my actionscript code?
Thanks, I appreciate it!
You're going to utilize the flash.external.ExternalInterface class.
Adobe docs: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html
A simple google search for "AS3 ExternalInterface example" will yield more than enough results to point you in the right direction.
http://painteddigital.com/2008/calling-flash-as3-functions-from-javascript/
In the flash add a callback for the javascript function:
import flash.external.ExternalInterface;
ExternalInterface.addCallback("sendTextToFlash", getTextFromJavaScript);
function getTextFromJavaScript(str):void {
trace(str);
}
In the html/js call it:
<script type="text/javascript">
var currentPage="Home";
function setCurrentPage(newPage) {
currentPage = newPage;
SendDataToFlashMovie(newPage);
}
Calling JS Function From Flash: getURL("javascript:myfunction();");
精彩评论