Load external script within Ext JS 4

Within Ext JS 4, I need to load D3 API. I am using the below code

	loadScript: function(callback, scope) {		console.log('5) loadScript called');      
		Ext.Loader.injectScriptElement('http://d3js.org/d3.v3.js', onLoad, onError);
	    console.log('D3 script loaded ');
    },


    onError : function() {
		console.log('On Error');
	},
	onLoad : function() {
		console.log('On Load');
		d3.select('body').append('div').style('position', 'absolute').style('padding', '0 10px').style('background', 'red').style('opacity', 0);
	},

Open in new window


However, in browser console, I get the below error -

Uncaught ReferenceError: onLoad is not defined

Can someone please help me rectify the above code?

Thank you.
LVL 1
ank5Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David S.Commented:
You've defined onLoad and onError as methods of some object. As such you have to reference them that way too. They are not variables within the scope of the currently executing code block.

If you would like further help, we'll need to see some of the surrounding JS code.
ank5Author Commented:
Got resolved by changing the code to -

loadScript: function(callback, scope) {
		Ext.Loader.injectScriptElement('http://d3js.org/d3.v3.js', this.onLoad, this.onError, this);
    },

    onError : function() {
		console.log('On Error');
	},
	
	onLoad : function() { 
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David S.Commented:
Congratulations on finding a solution. Apparently onLoad and onError were assigned as methods of whatever it is the special "this" object/keyword references when the loadScript method is executed.
ank5Author Commented:
The code provided in this solution solved the problem.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.