Call an javascript function from actionscript script - javascript

I am trying to build a button that will active specific Javascript function.
I tried:
getURL("javascript:functionName()");
but its seems like a bad idea (plus it doesn't work)..
or
import flash.external.ExternalInterface;
function call_javascript(evt:MouseEvent):void {
ExternalInterface.call("functioName()");
}
btn.addEventListener(MouseEvent.MOUSE_UP, call_javascript);
none of this working for me..

First of all, this is a duplicate. The question has been asked about 10 times before. But, here is an answer for you: ExternalInterface.call("jsFunctionName", argument, argument, ...);. It is very possible. Click here for more details.

Your problem is that you are calling it wrong. The 1st param should be the function name without the brackets: ExternalInterface.call("funcionName");
Also note that you will have to have allowScriptAccess set to a value that will actually allow you to call the function (in your example you have sameDomain, which is OK).

Related

Pass Component Name as Argument and then attach method (not working?)

Maybe I'm not using the right terms/names for my searches but I have not been able to find anything on this topic. I would have thought this would be an easy thing to find. What I'm doing is passing a component name to a function and then trying to use the component's name by attaching a method to it. I have confirmed (via Dev Tools) that the name is correctly being passed but when I use the variable and attach the method the specific request does not work. If I 'hard-code' the exact component name to the method it works perfectly. This makes me think the (various) ways I've been trying to attach the method to the variable name is incorrect (see various attempts below). Can you offer some direction here? Thank you.
Passing to Function ...
const grid_name = "grid_GroupA";
console.log(grid_name); // Shows grid_GroupA
msg_max(newItem, grid_name);
Function (only listing relevant parts)
function msg_max(newItem, grid_target) {
console.log(grid_target); // Shows grid_GroupA
// grid_GroupA.data.add(newItem); // This works ...
// grid_target.data.add(newItem); // This does not work
// (grid_target).data.add(newItem); // This does not work
// [grid_target].data.add(newItem); // This does not work
// grid_target + '.data.add(newItem)'; // This does not work
Thank you ...
Edit ...
In my attempt to provide detail I hope I haven't confused the issue.
In essence, my question is if I can type this exact string
grid_GroupA.data.add(newItem);
and it works for my function, how can I place a variable with the exact string "grid_GroupA" in front of ".data.add(newItem);" and have it seen the same as the line of code that works? Maybe my lack of knowledge here is getting in the way but isn't the line of code that works just a string that is then used to 'find' the object? So, if that assumption is correct, how do I create that same string with the variable? If my assumption is wrong I am a willing learner so I will be all ears. Thank you.
I do not see how grid_target is an object. You are passing grid_name(which is a string) to the function, so grid_target will have no data property, because string doesn't have such a member.
P.S. snake_case is bad option for JavaScript, consider using cameCase instead

Can't get it to work: Use value from one javascript function in another function

I'm practising with several javascript functions, which all work fine separately. But if I try to get a value from one function into another function I can't get it to work.
I've read multiple threads overhere (and elsewhere) and have been trying with several options like 'return', 'callback', console.log, merging the functions, etc.
No result for me... Could you help me?
My fiddle is:
Fiddle
I would like to use the value of variable 'direction' inside function geo() in another function: processSVData(). In processSVData I would use the direction 2 times.
Your code doesn't work because the function which accesses the direction variable accesses it before it is set. I've changed script ordering here and it works fine now: http://jsfiddle.net/bz2g5ong/7/
I cannot read the code but, as a general idea:
function iNeedData(preciousData) {
console.log(preciousData);
}
function iSendData() {
iNeedData("Wow, data!");
}
iSendData();

JavaScript not starting function

I have search for some sort of way to do this, but i can't make it work. It may seem simple but i don't know much about javascript so I have found very little information on the problem and I don't know were is the error at so i'll just briefly explain what it's supposed to do. First here is my code:
function showI(a){
$("#show").fadeIn();
$("#show .load").fadeIn();
$("#show").load("ajax/showi.php?id="+a,$("#show .load").fadeOut("fast"))
}
$('.List-item').on('click touchstart',function(){
var id=$(this).attr("id").split("list-").join();
showI(id);
})
So there's like a button with the class list-item which when click should open a new window with the showI function, but it doesn't(I used before the attribute onClick, but it didn't work on mobile so I changed it to .on(click touchstart))
Any help would be appreciate. (Don't know if this is replicated because i can't find a word to describe the problem)
This line:
$("#show").load("ajax/showi.php?id="+a,$("#show .load").fadeOut("fast"))
calls $("#show .load").fadeOut("fast") and then passes its return value into load as a second argument, exactly the way foo(bar()) calls bar and then passes its return value into foo.
If you're looking for a completion callback, you need to wrap that in a function:
$("#show").load("ajax/showi.php?id="+a, function() {
$("#show .load").fadeOut("fast");
});

Trying to understand js call()

I am trying to understand this line of code. it's from the blueimp jquery file upload. I've extracted the part I need down this line (it populates my page with images I already have). I am unclear as to why it needs to be called this way. I understand the call() method, just not clear on this - it seems extra convoluted:
$('#fileupload').fileupload('option', 'done').call($('#fileupload'), null, {result: data.images});
data.images is a JSON set of images. The code works, just unclear why I need to call things as they are.
Here's the original code - made for multiple fields it looks like)
https://github.com/blueimp/jQuery-File-Upload/blob/master/js/main.js#L53
$('#fileupload').fileupload('option', 'done') reads the value of the done option, which appears to be a callback function. As the function is not being invoked as a property of the $('#fileupload') element, the code has to call it so as to give it the expected value for this.

window.setInterval - is it possible to have more than one? how?

I have created a slideshow widget, using jQuery.UI widgets that works with window.setInterval.
I am trying to have more than one slideshow in the same page and i get the following results:
If I try invoking the same widget for both of my divs with images:
$('#div1').slideshow();
$('#div2').slideshow();
none of them work;
I have cloned the definition of my widget and named it slideshowsmall
$('#div1').slideshow();
$('#div2').slideshowsmall();
and only the second one works.
my widget code is in this pastebin, but i really think the problem, at least in the second try, has to do with setInterval
Thanks
Having multiple setInterval() by itself cannot be causing problems. It is more likely to have something to do with the code it's executing (and your widget code being non-english makes it very hard to analize and comprehend).
setInterval() returns and integer ID of the "interval", so that you can later clearInterval(...) by passing this ID. This scenario was implemented exactly for multi-interval uses. More details on MDC
As per your widget code when setInterval calls the ChangeLeft/Right.. method the slideshowdiv variable always points to the last element on which slideShow is called. the reason for this is the way you are invoking change methods which is not adviceable.
Please use the below code to call your change method it should solve your problem. You will notice I am passing the slideshowdiv object to change methods.
this.options.timer = window.setInterval(function () {
ChangeImageLeft(velocidade, slideshowdiv);
}, intervalo);
Let me know if you need more info.

Categories

Resources