How to fix: "NPMethod caused an error not related to NPObject wrapped JSObject"?

Hi

I am trying to call a method defined in a flash object from javascript (firefox-3.0 / Linux) and get an exception: "NPMethod called a non-NPObject wrapped JSObject".

If I use eval on window.document.flash_object.func (), it throws Msgstr "NPMethod called a non-NPObject wrapped with JSObject".

Where as if I define the javascript function on the side as follows:

function myFunc () {return flash_object.func ();

}

and then do eval from window.document.myFunc (), it works fine.

I run two analyzes through a test environment called Selenium. [eval (window.document.flash_object.func ()) and Eval (window.document.myFunc ())].

The problems seem to arise when calling the flash object method without passing the 'this' help. Here is a sample html / js code to reproduce this problem: "NPMethod called a non-NPObject wrapped by JSObject."

<script>
function changeColor() {
  mymovie.changeColor();
}
function getColorNP() {
 var func = mymovie.getColor;
 func();
}
</script>
<button type="button" onclick="getColorNP();">getColorNP</button>
<button type="button" onclick="getColor();">getColor</button>

getColorNP throws the exception
Error: NPMethod called on non-NPObject wrapped JSObject!
Source File: http://my.host/Colors/colors.html
getColorNP throws the exception
Error: NPMethod called on non-NPObject wrapped JSObject!
Source File: http://my.host/Colors/colors.html

Now the question for the javascript guru: Given the flash object and method name, how do I call the method for this object. Suppose a function takes two arguments: a flash object and a method name as a string. I want to do an eval on object.method () inside this function. Is this possible, if so, can you explain to me how this can be done.

Since the flash object method is not a standard javascript function, I think it is not possible to bind the binding using bind (). Is there any other alternative?

thanks Chandra

+3
source share
5

, - ( ) , . :

function getColorNP() { // this will call error
 var func = mymovie.getColor;
 func();
}

function getColorNP() { //this will work
 mymovie.getColor();
}

, - - , -. :

function getColorNP() { // this will work also
 var func = function(){mymovie.getColor()};
 func();
}

, - javascript, , .

+6

Flex/AS3 Javascript

, flex/flash:

FlashSelenium: Selenium RC, Selenium RC ActionScript Flex. FlashSelenium Flex . http://code.google.com/p/flash-selenium/

Selenium Flex API: Selenium IDE , Flex. http://code.google.com/p/sfapi/.

, (NPMethod -NPObject, JSObject!) firefox, , firefox javaScript Flash, JavaScript .

selenium * firefoxproxy.

,

+1

( )

+1
function callFlash(domobj, method_name){
    domobj[method_name]()
}
0

"NPMethod, , NPObject wrapped JSObject" / jQuery Flash :

    if (ExternalInterface.available) {
      ExternalInterface.addCallback("on_focus", on_activate);
      ExternalInterface.addCallback("on_blur", on_deactivate);
      ExternalInterface.call("eval", "if ($) $(window).focus($('object')[0].on_focus);");
      ExternalInterface.call("eval", "if ($) $(window).blur($('object')[0].on_blur);");
    }

, SWF, :

    if (ExternalInterface.available) {
      ExternalInterface.addCallback("on_focus", on_activate);
      ExternalInterface.addCallback("on_blur", on_deactivate);
      ExternalInterface.call("eval", "if ($) $(window).focus(function() { $('object')[0].on_focus() });");
      ExternalInterface.call("eval", "if ($) $(window).blur(function() { $('object')[0].on_blur() });");
    }
0

Source: https://habr.com/ru/post/1737384/


All Articles