我从localhost Xampp调用我的Main.swf,它在点击该按钮时包含一个提示按钮,提示单击功能被调用
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”按钮,单击“接受”按钮后,数据应发送到调用Main.swf。 我无法从javascript窗口调用我的Main.swf函数 通过AS3中的externalInterface回调
我发现当我将Main.swf嵌入到包含我的编辑器的同一窗口时它可以工作(externalInterface调用Actionscript),但我不想在编辑器页面上嵌入swf 有没有什么方法可以直接从javascript窗口调用swf而不嵌入?
答案 0 :(得分: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代码并使其更具动态性。
答案 1 :(得分: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);
}
虽然我正在发送字符串数据,但如果我尝试将图像数据作为对象发送到Flash,我的浏览器会挂起 我需要将图像数据发送到闪存。 我该怎么办才能发送数据?