I am trying to implement following:
How can I start a flash video from javascript?
However I am unable to call method from Javascript. The trace message I wrote within AS file is not able to see while calling file within browser.
How can I test whether my JS function is calling AS method or not?
The FlashBug addon for Firefox lets you see Flash trace outputs in your browser.
here is the code which I am using:
import flash.external.*;
var flashFunction:String =
"jsstopMainVideo"; var
realFunction:Function = stopMainVideo;
function stopMainVideo(){
trace("called from javascript");
//flvPlayer.stop(); }
//stopMainVideo();
var wasSuccessful:Boolean =
ExternalInterface.addCallback(flashFunction,
null, realFunction);
In JS I am doing:
var me = null; function
getID( swfID ){
if(navigator.appName.indexOf("Microsoft")
!= -1){
me = window[swfID];
}else{
me = document[swfID];
} } getID("signupVideoVideo");
me.jsstopMainVideo();
I am getting JS error that function me.jsstopMainVideo() is not a function
The simplest method is to create a javascript function that only has an alert function inside.
try calling it, you either get the pop-up or you don't.
edit:
Alert is a javascript command, but you can call it directly from flash using external interface call.
as:
var call_java:uint;
call_java = ExternalInterface.call('alert','!!!');
or... call the alert from a function
AS:
var call_java:uint;
call_java = ExternalInterface.call('myFunction','!!!');
javascript:
funciton myFunction(val)
{
alert(val);
}
Just check this example http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html , maybe you forgot something
Related
I need to rewrite a existing function which is created by the website when the page is loaded. The function is something like this:
function CheckStatus() {
var vcode = $.trim($("#insertCode").val()).toUpperCase();
var vreturn = encodeURIComponent(document.getElementById('text_return').value);
... (lots of other stuff)
}
And I would like to rewite this function to be like this:
function CheckStatus() {
return true;
}
If I paste this function in the chrome console, it rewrites with no problem. But when I try to do it with selenium It does not rewrite... I think it creates another function with the same name. My code in python using selenium webdriver is this:
driver.execute_script("function CheckStatus() { return true;}")
It does not return errors. Nothing happens actually.
Any clues how to solve this with selenium?
Thanks!
Solve it with something similar:
driver.execute_script("CheckStatus = function CheckStatus() { return true;}")
Thanks guys!
You're sending a function declaration. Nothing is executed here because you didn't ask to execute anything, you just defined a function. What you want looks more like this:
driver.execute_script("() => ({ return true;})()")
Don't forget to actually call you function at the end.
i'm not sure, but try to set the function to window object, maybe python's selenium has another name space
so:
driver.execute_script("window.CheckStatus = () => true;")
Okay so here is my problem my javascript is so,
var example = {
meep: function() {
alert("This alert or function does not happen using onclick D:");
}
}
Looks fine right? Okay so now when I do this,
<button onclick="example.meep()"></button>
It does not work and returns "Uncaught TypeError: undefined is not a function"
I can also do the function "example.meep()" in console and it works. I've tried it with and without ending parentheses.
try attaching the example to the window. Change
var example = {
...
to
window.example = {
...
This works:
<div id="result"></div>
<script type="text/javascript">
var Base64Encode = window.btoa || CryptoJS.enc.Base64.stringify;
document.getElementById('result').innerHTML = Base64Encode("Please work.");
</script>
However, this:
<div id="result"></div>
<script type="text/javascript">
var Test = {
Base64Encode: window.btoa || CryptoJS.enc.Base64.stringify
};
document.getElementById('result').innerHTML = Test.Base64Encode("Please work.");
</script>
Generates an error of "TypeError: 'btoa' called on an object that does not implement interface Window."
Fiddle:
http://jsfiddle.net/kAGU2/
Why does the first example work but the second one emit that error? What's the correct way to fix this particular error?
Why does the first example work but the second one emit that error?
When the function is called as Base64Encode(), the this context is implicitly set to window. However, when you call it as a method on Test.Base64Encode(), this will refer to Test and btoa grumps about that.
What's the correct way to fix this particular error?
You will need to bind it to the expected context:
Base64Encode = window.btoa
? window.btoa.bind(window)
: CryptoJS.enc.Base64.stringify;
Use .bind():
var Test = {
Base64Encode: function() {
if (window.btoa)
return window.btoa.bind(window);
return CryptoJS.enc.Base64.stringify;
}()
};
You got the error because you invoked the function via that object property reference. When you do that, the value of this is set to a reference to the object involved. The btoa() function doesn't like that (for who knows what reason), but .bind() creates a wrapper function for you that ensures the proper this.
It appears as that btoa function is a member function of Window class. And so it has to be called with this set to window.
In order it to work in your setup you should call it this way:
Test.Base64Encode.call(window,"Please work.");
My query is regarding using Javascript to change the value of an onclick function that already exists on the page.
There's a button. This button has the following onclick function:
onclick="if (confirm('Yahdy Yahdy yah?')) { someFunction(); }; return false;"
I would like to change the onclick function using Javascript to just be as follows and or extract the someFunction(); and run that directly without having to go through the confirmation. As I understand it, you can't confirm a confirm through scripting, so my only option is to run someFunction(); directly. My question is, how do I access someFunction() directly as someFunction() contains randomly generated values each time the page loads.
onclick="someFunction();"
That's basically what I'd like, so I can then call onclick() directly. I'm happy to use vanilla or jQuery to go about this.
TLDR: I want to extract PART of the old onclick function and make a new onclick function with JUST that part.
You can do this:
var code = obj.onclick.toString();
That will give you the javascript code assigned to that click handler to which you can search through it, find what you're looking for and reassign the click handler to something else.
I have no idea if this is the best way to do it, but here's something that worked for me:
function nullConfirm() { return true;};
(function() {
var obj = document.getElementById("test");
var code = obj.onclick.toString();
code = code.replace("confirm(", "nullConfirm(");
var matches = code.match(/\{(.*)\}/);
if (matches) {
obj.onclick = function() {
eval(matches[1]);
}
}
})();
In my current application I am using jquery UI dialog at many places , so I am planning to create a method like
var MYAPP = MYAPP || {};
MYAPP.overlay = (function(){
$("#id").dialog();
}());
This is my idea but now the problem is my overlay is used for different purpose like overlay form, video, confirmation message etc. Is there a way I can have all the option inside my API . so I just have to call MYAPP.overlay("video",some other parameter) and it will create the overlay without have to repeat the code again and again....any idea or suggestion will be appreciated..
I'm not sure what you are trying to accomplish with the immediately executing anonymous function, but you can do something like this:
MYAPP.overlay = function MYAPP$overlay(id, paramsObj) {
// do something based on element type, id, or params obj here.
$(id).dialog();
// possibly return something if needed.
};
yes you can use parameters. here is a very generic way of doing it:
MYAPP.overlay = (function(){
// complex code ....
return function(arg) {
alert(arg);
}
})();
// example
MYAPP.overlay('hello');
will alert hello