View Full Version : Confusion over dynamic loading and referencing by alias

10 Oct 2013, 2:37 AM
If I have the following app.js file:

Ext.onReady(function () {
Ext.define('myApp.myButton', {
extend: 'Ext.button.Button',
alias: 'myButtonAlias',
scale : 'large'

Ext.create('myButtonAlias', {
renderTo: document.body,
text : 'Click me'

.. and my index.html contains
<script src="ext/ext-all.js"></script> ... the button is correctly created. But if I change the index.html to:
<script src="ext/ext-dev.js"></script> ...it doesn't work. The dynamic loader is expecting to find 'myApp.myButton' in a "myButtonAlias.js" file. Is it possible to make the dynamic loader recognize that the class is already defined and allow the button to be created by reference to the alias or class name without it attempting to load it from another file? Or is it that when ext-dev.js is used classes must be in their proper place for MVC. If so I'm not clear how I would go about creating the class via the alias rather than class name.

10 Oct 2013, 2:45 AM
Ext.Loader.setConfig({enabled: true});
Ext.Loader.setPath('Ext.ux', '../ux');

Did you play with Ext.Loader ? that will automatically load classes for you when needed by the application.

In my case, I use "widgets", when the project is not MVC, you can define as you want and name the file with any name.

Ext.define('SampleGrid', {
extend: 'Ext.grid.Panel',
alias: 'widget.grid',

Ext.widget('grid', {
renderTo: 'grid'

Not sure if that may help you.

11 Oct 2013, 1:00 AM
No. That's not really answering the question. As the MyButton class is defined in the app.js it doesn't need to be loaded from anywhere. It's already loaded. I'm trying to use the alias to create the button and this works if ext-all.js is used, but if ext-dev.js is used it looks for a file called 'myButtonAlias.js' because it thinks I'm using the class name. How would you create a button by alias while using ext-dev.js? Is it essential that classes are defined in the appropriate file/directory when using ext-dev.js?

16 Oct 2013, 5:16 AM

16 Oct 2013, 5:48 AM
You need to trace into this method (http://docs.sencha.com/extjs/4.2.2/source/ClassManager.html#Ext-ClassManager-method-instantiate). However comments say, that it supports aliases. Maybe you need something like alias:'widget.myButtonAlias' (as usual for components) for it to start working?