I get "can't convert undefined to object" error while trying to run this piece of code. I'm not a programmer and can barely code therefore my question might be quite stupid/unanswerable for what I'm deeply sorry.
Code:
if (path == F[0])
{
//go N
if (pointAy > 0)
{
if (!(PS.BeadData(pointAx, pointAy - 1) === "blocked"))
{
// Set bead to Previous State
PS.BeadColor(pointAx, pointAy, previous_bead_NPC[NPCid][2]);
PS.BeadData(pointAx, pointAy, 0);
PS.BeadGlyph(pointAx, pointAy, " ");
// Increment
pointAy -= 1;
// Place NPC
MakeNPC(pointAx, pointAy, NPC[NPCid][2], NPC[NPCid][3], NPC[NPCid][4], NPC[NPCid][5], 1);
}
}
}
Can't really tell if this is enough to find an answer for you - I can post more of the code if it would help.
Maybe there is some generic answer to such an error a normal programmer would know, but such a noob like me will be oblivious to?
UPDATE
Ok, through step-by-step execution I found out that the error pops out in a different function even though disabling above piece of code makes the error not pop up. This is the function that makes the error pop up:
PS.Tick = function ()
{
"use strict";
for (var NPCid = 0; NPCid < 10; NPCid++)
{
NPCAI(NPCid);
};
};
This function is called every second and it calls AI logic function to move 10 NPC on a grid by supplying the NPCid to the AI function. Script fails here, but not always - usually one or two of the NPCs makes a step and only then the function fails.
If you are using Chrome or Firebug you can step through the JavaScript code. On Chrome, open up the tools icon (wrench in the upper right corner), then enable the developer tools by selecting "Tools" from the drop down menu and the "Developer Tools". At the bottom you should see a button in the lower part of your screen for scripts. Click on that and navigate to your page. When you see your JavaScript file open it and put a breakpoint at the "if" statement. Reload your page and then look at the values of PS and NPC when the debugger stops your code.
Related
I want to get the currentFrame of my Flash movie when it is loaded. I followed the the tutorial found here http://learnswfobject.com/advanced-topics/executing-javascript-when-the-swf-has-finished-loading/index.html and SWFOBJECT CurrentFrame Javascript. I am using SWFObject 2.3 beta. This works perfectly fine on Internet Explorer however it does not work on Google Chrome.
In Chrome I get the error
Uncaught TypeError: e.ref.currentFrame is not a function
Checking e it returns [object Object]
Checking e.ref returns [object HTMLObjectElement]
Checking e.ref.totalFrames returns undefined
var flashvars = {};
var params = {};
var attributes = {};
function mycall(e){
setInterval(function(){console.log("Frame: " + e.ref.currentFrame)},1000);
}
swfobject.embedSWF("notmyswf.swf", "course", "100%", "100%", "6.0.0", false, flashvars, params, attributes, mycall);
Why is this not working on Chrome but works well with IE? Is the event e not detected? Is there a work-around on how to make this work on Chrome?
The purpose of this is for me to create a check if the user is really using the course he has opened and not just leaving it idle. I have already added a code that will check idle but it is not enough. Most learners, have figured out a way to just open a course, leave it there to accumulate hours of training. Some even have a program running in their computers that will just move the mouse 1-pixel every few seconds so that the computer does not go to idle. If I can check the current frame of the Flash movie, I can create a function that will calculate the current page the user is viewing every 15 minutes. If he is stuck in the same page I can then show a prompt that the user must click in order to continue viewing the course or it will automatically close.
I suggest dropping the SWF-based currentFrame approach in favor of monitoring your calls to the database using JavaScript. (Based on your comments, it sounds like the DB calls are being sent by JS, so this shouldn't be a problem.)
If the course bookmark is auto-saved every 3 minutes (as described in your comments), you can cache the value in your page's JS and do a compare every time the save is performed. If the value hasn't changed in x number of minutes, you can display your timeout warning.
If you're using a SCORM wrapper (or similar), this is really simple, just modify the wrapper to include your timer code. Something like:
//Old code (pseudocode, not tested)
function setBoomark (val){
API.SetValue("cmi.core.lesson_location", val);
}
//New code (pseudocode, not tested)
var current_location = "";
var activityTimer;
function disableCourse(){
//do stuff to disable course because it timed out
}
function setBoomark (val){
API.SetValue("cmi.core.lesson_location", val);
if(val === current_location){
//do nothing, timer keeps ticking
} else {
//reset timer using new bookmark value
if(activityTimer){ clearTimeout(activityTimer); }
activityTimer = setTimeout(disableCourse, 15000);
//Update current_location value
current_location = val;
}
}
This is a rough sketch but hopefully you get the idea.
I feel stupid!
It did not work in Chrome and Firefox because I used the wrong casing for the functions but in IE11 it works no matter the case.
So the correct functions are:
e.ref.CurrentFrame() //I used currentFrame() which still works in IE11
e.ref.TotalFrames() //I used totalFrames() which still works in IE11
e.ref.PercentLoaded() //I used this correctly and was able to get the value
I am learning chrome extension programming from the tutorial here .
You can find the full code for the chrome extension here.
The code snippet where I tried to remove few links:
var clean_twitter = function(){
var ugly = [];
ugly.push('.Trends module trends');
ugly.push('.flex-module');
ugly.push('.MomentMakerHomeModule-header');
ugly.push('.Footer module roaming-module');
ugly.push('.flex-module-header');
$('.promoted-tweet').hide(); // oops! :P
for(var i=0;i<ugly.length;i++) {
var u = $(ugly[i]).find('a'); // also 'b'
u.text('');
}
}
The code tries to remove some buttons and div from the twitter website.
Now, when I put it on my pc nothing happens. I tried to remove the change link inside the trends box and it isn't removed.
Please help if I am doing something wrong here. Thanks.
At the beginning of the process_new_tweets function there's a comment explaining how the presence or absence of .mini-profile in the DOM is used as a flag.
In summary, the absence of the .mini-profile element in the DOM means that the function returns and won't proceed any further. Since the tutorial was written it would appear that Twitter no longer has a .mini-profile element anywhere in its DOM, so the function is always returning and script execution is not proceeding any further.
Remove the following lines from the beginning of the process_new_tweets function:
var mp = document.getElementsByClassName('mini-profile');
if(mp.length === 0) { return; }
And the elements that you've selected in your clean_twitter function will be removed from the DOM as expected.
This is the first time I get my hands on with automation instruments in xcode The script works well for all button taps but the one making server connection. I don't know the reason
Here is the script I tried so far
var target = UIATarget.localTarget();
target.pushTimeout(4);
target.popTimeout();
var window=target.frontMostApp().mainWindow()
var appScroll=window.scrollViews()[0];
appScroll.logElementTree();
UIATarget.localTarget().delay(2);
appScroll.buttons()[1].tap();
The above script works up to showing the UIActivityIndicator instead of moving to next controller after success
I know There must be a very simple point I am missing. So help me out
UIAutomation attempts to make things "easy" for the developer, but in doing so it can make things very confusing. It sounds like you're getting a reference to window, waiting for a button to appear, then executing .tap() on that button.
I see that you've already considered messing with target.pushTimeout(), which is related to your issue. The timeout system lets you do something that would be impossible in any sane system: get a reference to an element before it exists. I suspect that behind-the-scenes, UIAutomation repeatedly attempts to get the reference you want -- as long as the timeout will allow.
So, in the example you've posted, it's possible for this "feature" to actually hurt you.
var window=target.frontMostApp().mainWindow()
var appScroll=window.scrollViews()[0];
UIATarget.localTarget().delay(2);
appScroll.buttons()[1].tap();
What if the view changes during the 2-second delay? Your reference to target.frontMostApp().mainWindow.scrollViews()[0] may be invalid, or it may not point to the object you think you're pointing at.
We got around this in our Illuminator framework by forgetting about the timeout system altogether, and just manually re-evaluating a given reference until it actually returns something. We called it waitForChildExistence, but the functionality is basically as follows:
var myTimeout = 3; // how long we want to wait
// this function selects an element
// relative to a parent element (target) that we will pass in
var selectorFn = function (myTarget) {
var ret = myTarget.frontMostApp().mainWindow.scrollViews()[0];
// assert that ret exists, is visible, etc
return ret;
}
// re-evaluate our selector until we get something
var element = null;
var later = get_current_time() + myTimeout;
while (element === null && get_current_time() < later) {
try {
element = selectorFn(target);
} catch (e) {
// must not have worked
}
}
// check whether element is still null
// do something with element
For cases where there is a temporary progress dialog, this code will simply wait for it to disappear before successfully returning the element you want.
IE takes forever to load my GridView where as Firefox is almost instant (big surprise I know; but you know users and how they love IE).
We have a GridView which when the user scrolls to the bottom loads more entries into the list (basically lazy loading, instead of loading the whole list, it loads 20 entries and when you scroll to the bottom it loads the next 20). However like I said there is a huge difference in how this performs on IE vs FF. When debugging on IE I consistently get Javascript timeout errors.
during this code block:
function Sys$WebForms$PageRequestManager$_endPostBack(error, executor, data) {
if (this._request === executor.get_webRequest()) {
this._processingRequest = false;
this._additionalInput = null;
this._request = null;
}
var handler = this._get_eventHandlerList().getHandler("endRequest");
var errorHandled = false;
if (handler) {
var eventArgs = new Sys.WebForms.EndRequestEventArgs(error, data ? data.dataItems : {}, executor);
handler(this, eventArgs);
errorHandled = eventArgs.get_errorHandled();
}
if (error && !errorHandled) {
throw error;
}
}
This error AFAIK is the reason we implemented lazy loading (to get rid of the timeouts). However it seems to not be helping, merely duplicating the issue every time is runs. NOTE: prior to our last release it would load all the data as opposed to Lazy Loading.
Also when debugging it seems to cycle on this piece of code when it is "loading" on IE:
Protected Overrides ReadOnly Property ControlSkins() As System.Collections.IDictionary
Get
Return Me.__controlSkins
End Get
End Property
I believe due to fact that FF displays the data without the timeout that whatever is causing this is specific to IE and maybe common to other implementation of a GridView population.
I should note however that Im not positive that FF communicates with VS like IE does. Meaning that the warnings I get (the screenshot above) might happen on FF and VS doesnt show them to me but like I said FF has no problems with our page.
Followup [similar error q/a]:
After further testing the ControlSkins() method that is getting called repeatedly (posted above) here is its value. It alternates between that HybridDictionary and Nothing
I have to continue testing but I think/hope (fingers are crossed) that adding AsyncPostBackTimeout="300" on my ScriptManager (for that widget) has stopped the timeout error. Of course this doesn't help with the large load times on IE.
I've tried to ease my life by using Google Chrome's devtools and as I've tried to modify javascript of page on fly but it seems to behave unexpectedly
I have this function that is called every frame of the game
View.prototype.onHit = function() {
for(var i = 0; i < this.obstacles.length; i++) {
if(this.obstacles[i].dealsDamage) {
//deal damage
} else {
//do something else
}
}
}
and when I open it on chromes "Sources tab" and pause execution and add something simple such as
console.log("hey");
it starts printing text "hey" on console as expected but the moment i modify some code such as the if check to
if(!this.obstacles[i].dealsDamage) {
//do something else
} else {
//deal damage
}
inverting the behaviour and save the document, the code doesnt take effect and the logging source changes to View.js (old)
and anything I change after that doesn't affect the running javascript
The "(old)" script normally should only appear if the more complex changes are applied. Namely, if you change a function parameter number or start (and lamently stop) using a variable from outer scope.
If live edit fails to work in such simple use-case as you describe, it could be a good thing to file to http://crbug.com