Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 0.82 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. App.loadObject = function(type, name, params) {
  2.     if(App[type] == null) {
  3.         Ti.API.warn('Trying to load an object that does not exist in the App namespace');
  4.         return false;
  5.     } else if(App[type][name] == null) {
  6.         // If the name of the type object doesn't exist
  7.         Ti.include(type.toLowerCase() + '/' + name.toLowerCase() + '.js');
  8.         Ti.API.info(type + ' ' + name + ' Loaded');
  9.         return new App[type][name](params);
  10.     } else {
  11.         // If the name of the type object has already been loaded / exists
  12.         Ti.API.info(type + ' ' + name + ' Loaded');
  13.         return new App[type][name](params);
  14.     }
  15. };
  16.  
  17. /** Used in app **/
  18. // This will amount to 'new App.Controllers.List({ type: 'tasks', somearg: true });'
  19. var someThing = App.loadObject('Controllers', 'List', { type: 'task', somearg: true });