Passing variable from javascript to flash

北城以北 提交于 2019-12-13 08:39:09

问题


I have a flash 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!


回答1:


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();");




回答2:


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.



来源:https://stackoverflow.com/questions/7368687/passing-variable-from-javascript-to-flash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!