문제

I am calling my Main.swf from localhost Xampp which contains a prompt button upon click of that button promptclick function is called

AS3 code

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

}

this window (newwin) has a button "Accept" defined in "save.html" , upon click of Accept button the data should be send to calling Main.swf. I am not able to make a call from javascript window to my Main.swf function through externalInterface callback in AS3

I have found that when i embed Main.swf on the same window which contains my editor it works(externalInterface call to Actionscript), but i don't want to embed swf on editor page Is there any way i can make call to from javascript window to swf directly without embedding?

도움이 되었습니까?

해결책

Your code should be calling a javascript function which is defined outside. Example:

Javascript file:

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

Now change UrlRequest source to something like

"javascript: getFormWindow();"

or

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

and it is all handled from there simplifying your actionscript and javascript code and making it more dynamic.

다른 팁

I figured it out, I was calling swf object before it was loaded Here is my working callback code:-

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);
     }

Although i am sending string data but if i try to send image data as object to flash my browser hangs I need to send image data to flash. What should i do in order to send the data?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top