PDA

View Full Version : this.addEvents is not a function



jvolt
25 Feb 2010, 7:57 AM
Hello,

I'm using extjs and trying load js files using this function:


function loadScript(url, callback){

var script = document.createElement("script")
script.type = "text/javascript";

if (script.readyState){ //IE
script.onreadystatechange = function(){
if (script.readyState == "loaded" ||
script.readyState == "complete"){
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function(){
callback();
};
}

script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}


And i'm calling that using:


loadScript('global/js/base.js',function() {
//do something
});


But Ext returns an error:

this.addEvents is not a function
http://xxx.xxx.xxx.xxx/global/js/ext-3.1.1/ext-all.js
Line 7

What can be that?
Is there another way to load dynamically a js file?
I'vs tried a "plugin" called Ext.require, but get same error =(

jay@moduscreate.com
25 Feb 2010, 10:08 AM
could it be your code?

jvolt
25 Feb 2010, 10:22 AM
<script>
function loadScript(url, callback){

var script = document.createElement("script")
script.type = "text/javascript";

if (script.readyState){ //IE
script.onreadystatechange = function(){
if (script.readyState == "loaded" ||
script.readyState == "complete"){
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function(){
callback();
};
}

script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}

Ext.onReady(function(){
var win;
if(!win){
win = new Ext.Window({
layout:'fit',
width:390,
height:166,
plain: true,
closable: false,
title:"Login",
items: [
{
xtype:"panel",
layout:'column',
defaults: { border: false},
items: [
{
xtype:"panel",
html: '<img src="{{rootUrl}}global/img/logo.gif" width="100" height="100" />',
columnWidth: .25,
defaults: { border: false}
},
{
xtype:"form",
padding: '20px',
columnWidth: .75,
defaults: { border: false},
items:[{
xtype:"textfield",
fieldLabel:"Login",
name:"login"
},{
xtype:"textfield",
inputType: 'password',
fieldLabel:"Senha",
name:"senha"
}]
}]
}
],
buttons: [{
text:'Entrar',
handler: function() {
loadScript('global/js/base.js',function() {
//do something
});
}
},{
text:'Sair',
handler: function() {
window.close();
}
}]
});
}
win.show();
});
</script>


After press the "Entrar" button firebug shows the base.js file loaded, but also shows the errors:

this.addEvents is not a function
http://155.102.177.53/vsplus/global/js/ext-3.1.1/ext-all.js
Line 7