Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript到flash的无嵌入通信_Javascript_Actionscript 3_Callback_Window_Externalinterface - Fatal编程技术网

javascript到flash的无嵌入通信

javascript到flash的无嵌入通信,javascript,actionscript-3,callback,window,externalinterface,Javascript,Actionscript 3,Callback,Window,Externalinterface,我正在从localhost Xampp调用我的Main.swf,其中包含一个在单击按钮时发出提示的按钮promptclick函数被调用 AS3代码 function promptClick(event:MouseEvent):void { var desiredURL:URLRequest = new URLRequest("javascript:NewWindow=window.open('save.html','newWin','width=600,height=400,left =0,to

我正在从localhost Xampp调用我的Main.swf,其中包含一个在单击按钮时发出提示的按钮promptclick函数被调用

AS3代码

function promptClick(event:MouseEvent):void
{
var desiredURL:URLRequest = new URLRequest("javascript:NewWindow=window.open('save.html','newWin','width=600,height=400,left =0,top=0,toolbar=No,location=No,scrollbars=No,status=No,resizable=No,fullscreen=No'); NewWindow.focus(); void(0);");

navigateToURL(desiredURL, "_self");

}
此窗口(newwin)有一个按钮“接受”定义在“save.html”中,点击“接受”按钮后,数据应发送到调用Main.swf。 我无法从javascript窗口调用Main.swf函数 通过AS3中的外部接口回调

我发现,当我在包含编辑器的同一窗口中嵌入Main.swf时,它可以工作(外部接口调用Actionscript),但我不想在编辑器页面上嵌入swf
有没有什么方法可以直接从javascript窗口调用swf而不嵌入?

您的代码应该调用外部定义的javascript函数。例如:

Javascript文件:

var formWin,

formWinParams = {
    btnSelector: '.btn-on-form-win',
    name: 'windowNameHere',
    src: 'save.html',

    // Advanced string join (param could just be one long string instead)
    params: [
    'width=600',
    'height=400',
    'left=0',
    'top=0',
    'toolbar=No',
    'location=No',
    'scrollbars=No',
    'status=No',
    'resizable=No',
    'fullscreen=No'
    ].join(',')
},

swfFile;

/**
 * Gets a javascript object reference to a swf file
 * @return object
 * @note You should swfobject or jquery to get your swf file but 
 * you might also need to setup a mechanism to make sure swf file 
 * is ready for interaction (or swf load is complete)
 * @see example of load check http://abi.edu/js/new-video-gallery.js
 */
function getSwf (movieName) {
    if ( navigator.appName.indexOf( "Microsoft" ) != -1 ){
        return window[ movieName ];
    }
    else {
        return document[ movieName ];
    }
}

function onBtnClick (e) {
    swfFile.functionFromSwfFileHere();
}

/**
 * Gets form window lazily (if not there create it)
 * @return window object
 * @note Javascript function params are optional so we use the || operator to check if 
 * params are set otherwise we use our own values.
 */
function getFormWindow (src, name, params) {
    src = src || formWinParams.src;
    name = name || formWinParams.name;
    params = params || formWinParams.params;

    // Create window if not already created
    if (formWin === null) {
        formWin = window.open(src, name, params);
        // Setup handling of the form window button click
        $(formWinParams.btnSelector, formWin).click(onBtnClick);
    }

    // Bring window to front
    formWin.focus();

    return formWin;
}

// Wrap initialization of script for ease of use
function init () {    
    // Get reference to swf file
    swfFile = getSwf('swfFileIdHere');

    // Or use a library like jquery
    swfFile = $('#swf-file-id-here');
}

// Initialize javascript on window load (using jquery)
$(function () {
    init();
});
现在将urlRequestSource更改为

“javascript:getFormWindow();”

“javascript:getFormWindow('save.html','saveWin');”


这一切都从这里开始,简化了actionscript和javascript代码,使其更具动态性。

我想出来了,在加载swf对象之前,我调用了它 以下是我的工作回调代码:-

function onFlashReady() {
        sendToAS("value");
    }

    function callJS(value) {
        onFlashReady();
        return "Hi Flash.";
    }

    function thisMovie(movieName) {
         if (navigator.appName.indexOf("Microsoft") != -1) {
             return window[movieName];
         } else {
             return document[movieName];
         }
     }
     function sendToAS(value) 
     {  
         thisMovie("externalInterface").callAS(value);
     }
虽然我正在发送字符串数据,但如果我尝试将图像数据作为对象发送到flash,我的浏览器将挂起 我需要将图像数据发送到flash。
我应该怎么做才能发送数据?

让我直截了当地说:您有两个窗口,一个有swf,另一个有javascript函数。你想从swf调用javascript函数吗?是的,我想从swfI调用javascript函数,但我使用了externalInterface.call in Actionscript,它可以工作,但现在我在externalInterface回调中遇到了一个问题,在我的警报中,我可以:,通过window.opener.parent.document.getElementById('externalInterface').receiveTextFromJS(“伪文本”);\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuAS3代码:-ExternalInterface.addCallback(“receiveTextFromJS”,receivedTextAtAS);函数receivedTextAtAS(val:String){promptext.text=val;}另外,当我使用firebug在Firefox中调试时,我发现了错误类型error:receiveTextFromJS不是一个函数这是什么问题?我以前从未尝试将图像数据发送到flash。如果您需要flash中的图像数据,您应该创建一个类,该类利用flash的loader类来加载外部图像。我很久以前创建了一些类,但不太记得了,因为我几乎不再使用actionscript编写代码了。对于这个类,可以考虑像ExternalData这样的东西,它可以加载文本文件和图像文件。一旦加载了它的内容加载器信息数据,就可以转换成图像、位图或movieclip(如果内存足够的话)。查看actionscript文档,了解有关如何完成的更多信息(@see)