# How to Chain Controller Methods in Titanium by Using Alloy

Titanium and Alloy has as great feature to create controllers and be reactive to triggers or call methods without creating a pointer.

For the purpose of this tutorial, let's assume that we want to open a modal settings view and react to the settings being saved BEFORE closing the view. In this case, we might typically write:

var settings = Alloy.createController(“screens/settings”);
settings.getView().open({modal:true});
settings.on("saved", function( ){
  // do stuff here
  settings = null;
});

This approach is fine, but it’s a lot of code.

With Alloy, you can chain methods and do ALL this without ever creating the pointer variable:

Alloy.createController(“screens/settings”).on("saved", function( ){
  // do stuff here
}).getView().open({modal: true});

We can achieve the same thing in a few lines of code with no pointer created or potential memory leak issues.

This tutorial was originally posted in a blog post by Jason Keen (opens new window) entitled How to Chain Controller Methods in Titanium by Using Alloy (opens new window).