I have implemented a web page with Flash Player. And then I have used SetVariable keyword to give a param for a flash player object.
document.getElementById('flashPlayer').SetVariable("player.jsUrl","www.my.com/Songs/a.mp3");
It is working finely in IE and Chrome except Firefox. Which keyword is working concern it in Firefox?
P.S The error is "Error calling method on NPObject!".
Firefox can only use this function on the embed element, not the object element.
HTML
<object id="flashPlayer">
<embed id="flashPlayerEmbed">
</object>
Javascript
var player = document.getElementById('flashPlayer');
if(typeof(player.SetVariable) == 'undefined') {
player = document.getElementById('flashPlayerEmbed');
}
player.SetVariable("plyaer.jsUrl", "www.my.com/Songs/a.mp3");
I suspect that this is caused when trying to call the SetVariable call before the swf is loaded.
Try something like this:
function someTest() {
....
document.getElementById('flashPlayer').SetVariable("player.jsUrl","www.my.com/Songs/a.mp3");
}
And onload on body
<body onload="setTimeout('someTest();',500);">
Hope it helps
Related
With the update of Chrome from 43 to 44, the following syntax no longer works:
window.location.href = "javascript:alert()"
I'm trying to load the contents of a page from local storage. I'm doing this by returning the page contents as the result of a javascript function call. I need to specify a URL as the target for window. Rather than specifying http://...., I used to be able to specify javascript as the scheme in the URL and specify the name of the function to invoke.
Apparently, Google took this feature away in version 44. Has anyone run into this and figured out an alternative?
For others finding this page, it's an official bug now
The syntax is working for page itself, but not working for an iframe. This used to work in versions prior to Chrome 44. Even in Chrome 44, document is built and all events are fired, but the page won't be visible in iframe. The frame will start showing the contents if style attribute position for iframe is removed and added again. Here is the sample code illustrating workaround for Chrome 44.
chrome44.html
<html>
<script>
function getFrame(theFrameID)
{
return document.getElementById(theFrameID);
}
function loadFrameSource()
{
var aFrame = getFrame("frm");
aFrame.src = "chrome44frame.html";
// had to add the following line as a workaround for Chrome 44
aFrame.style.position = "absolute";
}
</script>
<body onload="loadFrameSource()">
<iframe id="frm" style="position : absolute;">
</body>
</html>
chrome44frame.html
<html>
<script>
function getHtml()
{
// Hard coding frame content for illustrating here, but actual script does more
return "<html> <body onload=\"document.getElementById('evnt').innerText='onload event fired.';\">href is Successful in changing html. <div id='evnt'>, but onload event didn't fire.</div></body> </html>";
}
function loadPage()
{
document.location.href="javascript:getHtml('href')";
// Had to add the following line as a workaround for Chrome 44
window.parent.getFrame("frm").style.position = "";
}
loadPage();
</script>
</html>
I have declared an object in HTML using the following code:
<object type="text/plain" id="clueBox" data="clues/random.txt" height="315" width="560"></object>
And then in my Javascript I have a function that looks like this:
function dummy(){
var box = document.getElementById("clueBox");
//alert(currentClue + " " + clueTypes[clueNum]);
box.setAttribute("type", "text/plain");
box.setAttribute("data", "clues/clue0.txt");
alert("Called Dummy");
}
Calling this function is supposed to update the clueBox object in the HTML. It works flawlessly in Firefox, but doesn't work at all in Safari. I need to make it work in Safari. Does anyone know how I can do this?
I did not have a problem with your code. I would check your error console in Safari and see if there may be a javascript error. You can open it by pressing Ctrl+Alt+C. Also is your alert getting fired?
I am having in issue with IE passing a string back into an swf using the EternalInterface class in Flash CS4.
I have an swf with the following code:
var externalString:String = ExternalInterface.call("IncomingJS")
which is inside an event listener attached to an Event.ENTERFRAME and an if statement waiting for ExternalInterface.available.
The IncomingJS function looks like:
function IncomingJS() {
return stringFromHTML;
}
and sits on the HTML page with the swf.
I am able to successfully get the externalString variable and procceed with the rest of the AS3 script in Firefox, Safari and Chrome, but not in IE.
If I add in an alert (stringFromHTML) before the return statement in the Javascript, I get the value of the stringFromHTML spammed, which looks like Flash is firing the function at the right rate.
The embed code in HTML for the swf is a little simple:
<object width="750" height="200" id="controlledScale"><param name="movie" value="http://www.myURL.com/controlledScale.swf"><param name="allowScriptAccess" value="sameDomain" /><embed src="http://www.myURL.com/controlledScale.swf" width="750" height="200" allowScriptAccess="sameDomain"></embed></object>
Any help or advice would be greatly appreciated.
Thanks,
DavidB
Edit
I realise how poor the SWF embed code is.
Unfortunately, the HTML code is actually working within a 3rd party HTML generator, and one of it's limitations is that I can only have a single line (with unlimited length) of html at a time.
Are the other options (swfObject etc) able to run either with no line breaks in the code, or would I be asking for trouble with Javascript and the SWF to, instead of embedding the SWF directly, use something like an iFrame and refer to a 'proper' flash delpoyment html file?
Kind of at a point on this one where I'm not even sure where the problem is actually located. The swf's are find sending out to Javascript across all browsers, just not getting info back in IE only.
You must add an id to the object tag to work in IE.
<object width="750" id="myflash" height="200"><param name="movie" value="http://www.myURL.com/controlledScale.swf"><param name="allowScriptAccess" value="sameDomain" /><embed src="http://www.myURL.com/controlledScale.swf" width="750" height="200" allowScriptAccess="sameDomain"></embed></object>
I pretty sure there is a security "feature" in IE that stops JS being called too many times from Flash, to stop it crashing the browser.
Is there a reason why you have to call it every frame?
I'd suggest against this at all costs as it's putting a LOT of extra stress on the browser.
***** EDIT *****
If you want to call an ExternalInterface method from JS -> Flash in IE you have to reference the object slightly differently, like this:
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
}
Then once you're sure the string you want to pass is constructed correctly you can call it like this from the JS:
thisMovie( "theFlashElementID" ).giveMeMyStringAlready();
Then in your Flash you would have something like this:
if( ExternalInterface.available )
{
ExternalInterface.addCallback( "giveMeMyStringAlready", handleTheStringFromJS );
}
else
{
handleTheFactIDontHaveExternalInterfaceAvailable();
// the only reason this would be is if container that
// is embedding the swf isn't fully loaded by the browser
}
The standout line from the AS3 docs regarding ExternalInterface is this:
Note: When using the External API with
HTML, always check that the HTML has
finished loading before you attempt to
call any JavaScript methods.
This:
Unfortunately, the HTML code is
actually working within a 3rd party
HTML generator
is the problem.
The swf is sitting inside a <form> tag.
At the browser stage, there is a huge volume of really verbose code, and I missed the tags at the very beginning and end of the html code.
Thanks for the help. If I have learnt nothing else from the experience, it's to be full with the question and look well beyond the immediate problem, breaking each element down as fully as I can.
i'm trying to call a method inside a flash movie from js, every time the mouse leaves the "div".
It works on Internet Explorer, but not in firefox. any ideas?
here is the html script:
<script type="text/javascript">
window.onload = function(e){
init();
}
function init(){
document.getElementById('div').onmouseout = function(e) {
method();
}
}
function method(){
flashid.anothermethod();
}
</script>
and the flash script:
import flash.external.ExternalInterface;
function outdiv(){
//do something;
}
ExternalInterface.addCallback('anothermethod', outdiv);
Any ideas what's wrong?
EDIT: here is example of the problem, there is an alert for the js and the flash should be able to remove the swf (see a gray background? it works! see a image, flash didn't receive the call):
http://complexresponse.com/out/addcallback_ff.html
this should work with internet explorer / safari / chrome (pc/mac) only firefox seams to reject this.
the problem is that the event probably doesn't fire because of the flash. try to handle the mouseout event in the flash on your main movieclip and see if it fires
Ensure that you're embedding flash with wmode set to "transparent". If not you won't get JavaScript events for DOM objects behind the flash object.
Is there a way to set focus to the embed HTML element using JavaScript? Test case: embedded YouTube videos on a page.
I have no control over the embedded Flash element. So, is there a way to set focus on it by using only JavaScript?
I read somewhere that calling the element.focus() method works only in IE. I need a browser-independent way that works in Chrome/Firefox.
Thanks!
This only works in Internet Explorer.
http://kb2.adobe.com/cps/155/tn_15586.html
I've tried to do this too, and ended up to a nice solution using jquery:
var gotoflash=jQuery("#flash_file").offset().top;jQuery("html:not(:animated),body:not(:animated)").animate({ scrollTop: gotoflash}, 1000);
where: <div id="flash_file"> flash object code here </div>
It can be done by adding flash content dynamically, for example with swfobject.
I haven't confirmed this, but you could try:
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
}
// Call from within another function:
thisMovie("FlashObjectID").focus();
thisMovie("FlashObjectID").showFlash();
// showFlash() is an AS3 ExternalInterface call from JS to .swf which establishes the TextInput.setFocus(); method
source: http://www.htmlforums.com/archive/index.php/t-64150.html