1

我从 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”中定义的按钮“Accept”,点击Accept按钮后数据应该被发送到调用Main.swf。我无法通过 AS3 中的 externalInterface 回调从 javascript 窗口调用 Main.swf 函数

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

4

2 回答 2

0

您的代码应该调用外部定义的 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();
});

现在将 UrlRequest 源更改为类似

"javascript: getFormWindow();"

或者

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

这一切都是从那里处理的,简化了您的操作脚本和 javascript 代码并使其更具动态性。

于 2012-12-23T06:43:19.367 回答
0

我想通了,我在加载之前调用了 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);
     }

虽然我正在发送字符串数据,但如果我尝试将图像数据作为对象发送到闪存,我的浏览器会挂起,我需要将图像数据发送到闪存。我应该怎么做才能发送数据?

于 2012-12-24T06:58:51.180 回答