I have an AS2 Flash SWF that is calling another AS2 Flash File using loadMovieNum("flash.swf",2) and a JavaScript file that calls a function on page using a timer. This is what I get in Firefox with Flash 10 (IE8 gives no error message):
uncaught exception: Error calling
method on NPObject! [plugin exception:
Error in Actionscript. Use a try/catch
block to find error.].
What is going wrong? I can't see a problem. It is suppose to clear the contents of the embedded swf and use a Flash alert dialog to confirm Yes or No.
Flash:
import flash.external.ExternalInterface;
import mx.controls.Alert;
System.security.allowDomain("mydomain.com");
function getTimeOut()
{
// Show alert dialog box
_level2._visible = false;
Alert.show("You are about to Timeout. Do you want to continue using Courseware?", "Timeout", Alert.YES |
Alert.NO, this, myClickHandler);
}
ExternalInterface.addCallback("timeOut", this, getTimeOut);
this.onMouseDown = function(){
//if not on login
getURL("javascript:startTimer();");
};
var myClickHandler:Function = function (evt_obj:Object) {
switch (evt_obj.detail) {
case Alert.YES :
getURL("javascript:buttonEvent('yes');");
break;
case Alert.NO :
getURL("javascript:buttonEvent('no');");
break;
}
_level2._visible = true;
};
//load courseware
loadMovieNum("embedded.swf",2);
JavaScript:
<script type="text/javascript">
// <![CDATA[
var so = new SWFObject("main.swf", "mainMovie", "100%", "100%", "9", "#083770");
so.addParam("scale", "noscale");
so.addParam("quality", "high");
so.addParam("allowScriptAccess","always");
so.write("flashcontent");
var timerMin = '<?php echo($timerMinutes); ?>';
var timer;
var timer2;
function startTimer()
{
var timerMill = 0;
clearTimeout(timer);
timerMill = getMillis();
timer = setTimeout ( 'stopTimer()', timerMill );
}
function stopTimer()
{
clearTimeout(timer);
timer2 = setTimeout( 'redirectPage()', 60000);
//call flash function
getFlashMovie("mainMovie").timeOut();
}
function buttonEvent(evt)
{
if(evt == 'yes')
{
clearTimeout(timer2);
startTimer();
}
else
{
clearTimeout(timer2);
redirectPage();
}
}
function getMillis()
{
var milliseconds = 300000;
if(timerMin == parseInt(timerMin))
{
//convert to milliseconds
//60000 milliseconds in 1 minute
milliseconds = (parseInt(timerMin)) * 60000;
}
return milliseconds;
}
function getFlashMovie(movieName)
{
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
//return document.getElementById(movieName);
}
function redirectPage()
{
top.location = "timeout.php?t=<?php echo($timerMinutes); ?>";
}
// ]]>
</script>
Same old story - NPObject.
I took Flash out of the picture and was able to achieve the same thing using CSS and JavaScript. The fix for this is to create a policy file for Flash but for something so simple I just went another direction so not to debug.
Related
I built a website using PHP & JavaScript and also I built an android WebView activity each page in website have a activity in android i'm trying to setTimeout in JavaScript 10 sec and this timeout will update when user clicked anywhere on screen , JavaScript code :
var timer = null;
timer = timerAction();
$(window).click(function () {
clearTimeout(timer);
timer = timerAction();
});
function timerAction() {
return setTimeout(function () {
showToast("Timeout relogin agagin");
loadNewPage('LoginActivity');
}, 10000);
}
and my android code to going another page :
#JavascriptInterface
public void loadeNewPage(String page) {
if (page.equalsIgnoreCase("MainMenuActivity")) {
Intent intent = new Intent(context, MainMenuActivity.class);
finish();
startActivity(intent);
}
}
my problem , example : if i clicked 10 times on screen timeout it will called 10 times again .
i know its bit late anyway please go through this , it may help you
function Timeout(fn, interval)
{
var id = setTimeout(fn, interval);
this.cleared = false;
this.clear = function () {
this.cleared = true;
clearTimeout(id);
};
}
var t = new Timeout(function ()
{
console.log("Cleared function");
t.clear();
showToast("Timeout relogin again");
loadNewPage('LoginActivity');
}, 5000);
$(window).click(function () {
if (t.cleared)
{
t = new Timeout(function ()
{
console.log("Cleared function");
t.clear();
showToast("Timeout relogin again");
loadNewPage('LoginActivity');
}, 5000);
}
else {
console.log("one time out funtion already running ");
}
});
Using Tampermonkey to change the behavior of a website. Have some problems with a website with the following code:
<script language="JavaScript">
if (typeof jQuery != 'undefined') {
jQuery(window).load(function() {
window.setTimeout(function() {
window.location.replace(window.location.href);
}, 180E3);
});
}
</script>
How does one remove/prevent it reloading the page?
Without messing that much with jQuery, if your script runs before that piece of code you can do the following:
jQuery.fn.load = function() {
console.log("Tried to reload the page!")
}
// Then the following, outputs 'Tried to reload the page!' and does nothing else
jQuery(window).load(function() {
// code
})
If you still need the load function afterwards you could do the following:
var oldLoad = jQuery.fn.load
var undesiredCallback = "function() {
window.setTimeout(function() {
window.location.replace(window.location.href);
}, 180E3);
}"
jQuery.fn.load = function(callback) {
if(callback.toString() !== undesiredCallback) {
oldLoad(callback);
}
}
But it's browser dependent and very unreliable
Another way would be adding a onbeforeunload event, but that would pop a prompt on your tab:
window.onbeforeunload = function() {
return "Stay here please";
}
You can also override setTimeout functionallity.
var oldSetTimeout = window.setTimeout;
window.setTimeout = function(func,interval){
if(typeof func === "function" && func.toString().indexOf('window.location.replace(window.location.href)') > -1){
/*do nothing*/
}else{
oldSetTimeout(func,interval)
}
}
I am new to Javascript... like super new :X and i am writing my very first script to try and automate video episodes of my favorite anime because the videos on the site don't have a autoplay feature after you click the link. I read about Video and Var = 'My video' to try and figure out how to tell the script, when page loads video .autoplay = true...but i just get to dead ends. here is where i am at:
var urlsToLoad = [
'http://Site1/Ep1',
'http://Site1/Ep2',
'http://Site1/Ep3',
'http://Site1/Ep4'
];
if (document.readyState == "complete") {
FireTimer ();
}
window.addEventListener ("hashchange", FireTimer, false);
function FireTimer () {
setTimeout (GotoNextURL, 5000); // 5000 == 5 seconds
}
function GotoNextURL () {
var numUrls = urlsToLoad.length;
var urlIdx = urlsToLoad.indexOf (location.href);
urlIdx++;
if (urlIdx >= numUrls) urlIdx = 0;
Once the first video link starts 'Site1/EP1', i have this going:
function myFunction() {
var vid = document.getElementById("925664"); <--Ctrl+F 'Videoid' from Source
vid.autoplay = true;
vid.load();
}
but it just stays died like 'click play to start' ..
I can really use help here PLZZZ and thank you.
Something like this:
<!-- HTML Page -->
<video id="925664"></video>
// Javascript
function myFunction() {
var vid = document.getElementById("925664"); // <--Ctrl+F 'Videoid' from Source
vid.src = "path/to/file.mp4";
//vid.autoplay = true; // not really anything that's useful
vid.load();
vid.play();
}
Warning: Most mobile devices don't allow media files to play via code and require human interaction (click/touch) in order to start playback. However, on desktops this isn't a problem.
Try using the play() method instead.
function myFunction() {
var vid = document.getElementById("925664");
vid.play();
}
There is a countdown in a page. And i want to bypass or speed it up.
Is there a possibility to run add ticket function from chrome's console or something?Or can I change the xtime variable to something like 2-3 seconds.Or directly call the add ticket function?
jQuery(document).ready(function($){
var xTime=120;
$("#ticketTimer").html(xTime);
var myVar = setInterval(
function(){
if(typeof checkAdBlock === 'undefined')
{
document.getElementById("compt").innerHTML = "<b>you use an AdBlocker!</b> To win a ticket, <b>Desactivate AdBlock and reload the page.</b>";
return false;
}
else if(xTime>0)
{
xTime--;
$("#ticketTimer").html(xTime);
}
else
{
addTicket();
clearInterval(myVar);
}
},
1000);
});
I'm trying to write an Android app with PhoneGap that contains multiple HTML files. In every HTML I would like to include an mp3 file that the user can play and stop. This has worked so far. The problem that I encounter is when trying to put multiple mp3 files in one file.
The thing that I would like to achieve is to put the general audio player javescript in one file and to tell in the HTML which file should be played. Is this possible and how? Thanks!
My code for one of the html files looks like this:
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" charset="utf-8">
//-------------------------------------------------------------------------
// Audio player
//-------------------------------------------------------------------------
var media1 = null;
var media1Timer = null;
var audioSrc = null;
/**
* Play audio
*/
function playAudio(url) {
console.log("playAudio()");
console.log(" -- media="+media1);
//var src = "/android_asset/www/audio/01.mp3";
var src = "/android_asset/www/audio/01.mp3";
if (url) {
src = url;
}
// Stop playing if src is different from currently playing source
if (src != audioSrc) {
if (media1 != null) {
stopAudio();
media1 = null;
}
}
if (media1 == null) {
media1 = new Media(src,
function() {
console.log("playAudio():Audio Success");
},
function(err) {
console.log("playAudio():Audio Error: "+err);
setAudioStatus("Error: " + err);
},
function(status) {
console.log("playAudio():Audio Status: "+status);
setAudioStatus(Media.MEDIA_MSG[status]);
// If stopped, then stop getting current position
if (Media.MEDIA_STOPPED == status) {
clearInterval(media1Timer);
media1Timer = null;
}
});
}
audioSrc = src;
// Play audio
media1.play();
if (media1Timer == null) {
media1Timer = setInterval(
function() {
media1.getCurrentPosition(
function(position) {
console.log("Pos="+position);
if (position > -1) {
setAudioPosition((position/1000)+" sec");
}
},
function(e) {
console.log("Error getting pos="+e);
setAudioPosition("Error: "+e);
}
);
},
1000
);
}
// Get duration
var counter = 0;
var timerDur = setInterval(
function() {
counter = counter + 100;
if (counter > 2000) {
clearInterval(timerDur);
}
var dur = media1.getDuration();
if (dur > 0) {
clearInterval(timerDur);
document.getElementById('audio_duration').innerHTML = (dur/1000) + " sec";
}
}, 100);
}
/**
* Pause audio playback
*/
function pauseAudio() {
console.log("pauseAudio()");
if (media1) {
media1.pause();
}
}
/**
* Stop audio
*/
function stopAudio() {
console.log("stopAudio()");
if (media1) {
media1.stop();
}
clearInterval(media1Timer);
media1Timer = null;
}
/**
* Set audio status
*/
var setAudioStatus = function(status) {
document.getElementById('audio_status').innerHTML = status;
};
/**
* Set audio position
*/
var setAudioPosition = function(position) {
document.getElementById('audio_position').innerHTML = position;
};
</script>
</head>
<body>
<!-- Audio -->
<div id="info">
<h2>Audio</h2>
</div>
Play
Pause
Stop
</body>
You might consider using a page with a frame on it. Place your common javascript in the of the main page and then call back to parent.playAudio(src) to kick off the player from each sub-page as it's loaded into the frame.
Another possible direction is use of jqMobile. By default, jqMobile loads pages using Ajax calls..consequently, your javascript can be loaded by the very first page only...and all subsequent page loads via ajax do not totally replace the DOM...leaving your javascript in tact. I have developed a small app using phonegap and jqMobile with fairly good success.