Uncaught reference error: slider is not defined - javascript

I'm trying to implement joss benner's fix as shown here. I need to implement this code:
slider.setOpts = function(opts) {
for (var opt in opts) {
vars[opt] = opts[opt];
}
slider.setup();
}
slider.getOpts = function() {
return vars;
}
I've tried with this fiddle here, but I just get
Uncaught ReferenceError: slider is not defined
in the console. Not really what I'm doing. The other commenters seem to be able to implement it no problem.
Could someone also explain the meaning behind the code... what is slider? A class? A function? Where should I place the above code to add the .setOpts function?

He wrote
I added these public methods to flexslider
To do so, you have to add those lines of code inside the jquery.flexslider.js-file and not in another js-file as you did in the fiddle. The error tells you what the problem is. And in your case, slider is in fact not defined, because the slider-variable is being declared inside a codeblock of the jquery.flexslider.js which means, there is no reference to this variable outside of this block.
The public methods start in line 426, so add your code there.

Related

Cocos2d js onTouch doesn't recognize local variables

I have this problem with an onTouchBegin function in which I want to update the position of a sprite on screen. However if I use this line of code inside of the update function is works flawlessly.
this.sprite.x += 5;
Now if I put this line of code inside the onTouchBegin or any onTouch method I receive this error "Uncaught TypeError: Cannot read property 'x' of undefined".
When I debug this inside the chrome console the local variables to the current js file exist and are shown as being instantiated variables with all properties and attributes attached. Then when I click the screen the debugger pauses inside the onTouchBegin function. At this point all the variables seem to be outta scope because they all show up as undefined or NaN or something else.
I cannot figure why this happening if anyone can give me some insight on how to fix this that would be appreciated.
So apparently in the callback function when the callback is returned the event parameter has some attributes attached to it one of the being called getCurrentTarget. This returned the js file that contained all the variables that were properly being used in the update function.
onTouchBegan:function(touch, event)
{
var target = event.getCurrentTarget();
},

TypeError: R[o5R.F6s] is not a function in changing states in phaser box2d

i build my game using phaser.2.4.3.min.js and phaser.2.2.2.box2d.min.js
When trying to change states this error is being raised TypeError: R[o5R.F6s] is not a function and i can't seem to figure out the problem
PS : i took The source code of box2d plugin from the example folder in phaser , and i did not purchase the full plugin yet i was just testing it .
is there anyway to fix this issue ?
here is the game code : http://jsfiddle.net/fbdtq1tg/5/
and here where the error is raised :
SetGameOver: function () {
this.game.state.start("TheGame");
}
The error seems clear: the script is trying to execute a function, but this variable isn't a function.
What happens: box2d.m_gravity = box2d.clone(); but R[o5R.F6s]() is the string "clone" and not a function. R = box2d, so the the script is trying to execute a function(R[o5R.F6s](). o5R is an object with a lot of functions in it but the requested F6s is a string("clone").
So, I did some research why box2d.b2world = function(gravity){...this.m_gravity = gravity.Clone();.. } and it seems to be a bug.
Check out following links:
http://www.html5gamedevs.com/topic/13753-changing-states-with-box2d-causes-crash/
https://github.com/photonstorm/phaser/issues/1884

TypeError: prc.cng() is not a function in Firefox, Uncaught TypeError: Object #<HTMLInputElement> has no method 'cng' in Chrome

I am writing a small library for internal use in a project that I am working on, I am an amateur Javascript developer, so mind my mistakes please.
I have written a small html file as well as javascript below it goes,
<html>
<head>
<script>
var prc = {
cng : function(evt){
console.log(evt);
}
}
</script>
</head>
<body>
<input type='text' id='prc' onkeydown="prc.cng(window.event)"/>
<body>
</html>
I tried executing this in Firefox and Chrome, not in IE Still,
When I am trying in Firefox, it gives this error "TypeError: prc.cng is not a function", and when trying in chrome it gives the "Uncaught TypeError: Object #<HTMLInputElement> has no method 'cng'".
I tried searching for this in StackOverflow, but the issues they are facing is quite different from what I am facing. Almost most of the issues faced were with jQuery involved, here please note that I am not using any kind of library and writing with plain old Javascript.
Any Help would be appreciated to enhance my understanding of the issue.
Having an element with an id that is the same as an existing JS variable is blatting the content of the variable and replacing it with a reference to the element.
The quick solution is to change either the variable name or the element id.
A more robust solution would be to keep all your data in as narrow a scope as possible. If you don't desperately need it to be global, then don't make it global and it won't be over-writable from outside the script.
Since, using intrinsic event attributes, you can only refer to variables in <script> elements if they are global, this is also a good time to stop using them and move to something modern.
// Self-executing anonymous function expression used to limit scope
(function () {
// Locally scoped prc that won't clash with the element
var prc = {
cng : function(evt){
console.log(evt);
}
}
// Event handler binding
document.getElementById('prc').addEventListener('keydown', function (evt) {
prc.cng(evt)
});
}());
Note that this script doesn't delay execution until load or domReady so place it after the input so that the input exists when the attempt to find the event handler happens.
I have found the answer to my own question, thanks to #Barmar, who has been instrumental in making me understand the problem.
When i define any element in html like this
<input type='text' id='test' onkeydown='test.fn()'/>
It means that an object is created by the browser for the same. So If I have javascript written which clashes with the id, that won't be accessible anywhere in that page.
<script>
var test = {
fn : function(){
console.log('test');
}
}
</script>
So Ideally either rename the id, or rename the object.

dojo.declare: unknown base class - dojo.Stateful

So I'm learning Dojo and seeing what I can do with it - I do apologise if this is a stupid question but I can't find a solution.
My code:
dojo.require("dojo.Stateful");
dojo.declare('W.Model',dojo.Stateful,{
foo:'bar'
});
The error:
Uncaught Error: declare W.Model: unknown base class. Did you use dojo.require to pull it in?
I did use dojo.require to pull it in. What am I missing?
Edit - console.log(dojo.Stateful); returns undefined. I am using Google to hot Dojo for me - here: <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js"></script>
Other classes are loading fine, just dojo.Stateful is a problem.
Do you have the full class declaration in a separate file? Or is this all inline on a page?
If you are doing it inline, wrapping the class until the page has loaded will fix the problem:
dojo.require("dojo.Stateful");
dojo.ready(function() {
var x = new dojo.Stateful();
console.log(x);
dojo.declare('some.class', dojo.Stateful, {
'x':'y'
});
});

yui3 widget error "this.constructor.NAME is undefined"

I am creating a yui3 widget and I keep getting this error: this.constructor.NAME is undefined.
I am defining a name in my widget:
YUI().add('paginator', function(Y) {
function Paginate(config) {
Paginate.superclass.constructor.apply(this, arguments);
}
Paginate.NAME = "paginate";
...
So, I am not sure what's going on.
Edit:
I also wanted to add that I have just tried to add the default widget skeleton from here and I am still getting the same error.
I thought I would answer this myself in case anyone else comes across this problem. I forgot the new keyword when creating my widget.

Categories