Skypanther Studios
  • Home
  • Door2Door
  • About

Breakpoint debugging an Alloy app

Leave a Comment

Today’s tip came out of a chat I had with the brilliant Aaron Saunders (@aaronksaunders). Thanks Aaron!

First, a little backstory. Appcelerator’s new Alloy framework provides an MVC-like development architecture for your Titanium mobile app development projects. In essence, Alloy is a preprocessor. You create views (in XML and CSS-like files), controllers, and models, which are all parsed and processed when you build your app. During the build process, the Alloy preprocessor creates the kind of “traditional” Titanium code you might have written in the past. That generated code is what ends up running inside your app.

The lines on which you set your breakpoint (in the source Alloy files) don’t correspond to the actual Titanium JavaScript that ultimately runs within your app. And without jumping through enormous hoops, you can’t set breakpoints in the generated code and run that code. In my testing, setting a breakpoint on an Alloy source file results in the debugger stepping line by line through your entire app’s code. Not very helpful.

Cue Aaron’s tip. You can add a statement to your code that will be treated like a breakpoint. Here’s an example:

// $.table represents a TableView
$.table.addEventListener('click', function(e) {
   // this is the 'magic' line:
   debugger;
   alert('You clicked row ' + e.rowData.id);
});

With that debugger statement in your code, do a debug build. Click this button:

debugbuild.png

Your app will compile and load into the simulator/emulator. When you click a row in the table, the debugger statement will be hit, the app will stop and the Studio debugger view will be activated. From there, you’ll have access to all the normal breakpoint debugging features offered by Studio. Key point: the correct line in the source file is highlighted! Breakpoint debugging is back with Alloy.

Debug window

 

 


Titanium graphs with a WebView



Titanium graphs with a WebView

Got data to graph in Titanium? On its own, Ti doesn’t provide a graphing component. There is an iOS-only module in the Marketplace. But if you also need to support Android or want other graph types, you’re out of luck. Fortunately, we can use the WebView, a suitable HTML graphing library, and some app-level events [...]

READ MORE »
Titanium

See the Mac Console for full error details



See the Mac Console for full error details

I got a (probably not so) bright idea about how to do a bulk update of my app’s database as part of a version upgrade. I could generate a SQL file containing all the statements that needed to be run by exporting from my desktop DB tool. Then I’d package the file with my app [...]

READ MORE »
Titanium

Split window editing in TiStudio



Yes, you can edit the same file in two tiled windows in Titanium Studio! Today I figured out how to do this and whipped up this short tutorial video just for you.

READ MORE »
Titanium

Delete a member of an array



Delete a member of an array

Here’s a quickie: Need to delete a member of an array in JavaScript? The traditional way is with the splice() method. Here’s an alternative using filter(): var deleteFromArray = function(array, valToRemove) { return array.filter(function(member) { return member !== valToRemove; }); }; Demonstrated in the JavaScript console: The filter() method examines each member of your array [...]

READ MORE »
JavaScript

Web site relaunch



I’ve set up WordPress as part of an overall site refresh. I migrated a few of my past Tumblr posts, the ones that were worth keeping. Much of my former site’s contents are gone. Sorry for the 404s but a lot of that content has been around for so many years that it is totally [...]

READ MORE »
Uncategorized

ADB hung? Restart it without closing the emulator



ADB hung? Restart it without closing the emulator

I find that occasionally adb loses touch with the fact that an emulator is running. I build my project only to get an error that adb timed out waiting for the emulator. I used to close the emulator, rebuild the project in Studio to relaunch the emulator, and wait, and wait. I discovered that you [...]

READ MORE »
Titanium

Is your Titanium app running on a tablet?



Is your Titanium app running on a tablet?

On a recent Titanium Mobile project, I found my app’s layout got all screwy when running on an Android tablet. To be more precise, on 10-inch class tablets (like the Xoom or ASUS Transformer), buttons and other elements were not positioned correctly. For whatever reason, the 7-inch tablets seemed to be fine. The problem is probably caused [...]

READ MORE »
Titanium

Scaling the Android emulator



Scaling the Android emulator

You can resize a running Android emulator by setting the window’s scale factor. You’ll need to telnet to the running emulator. Then, just enter the window scale command. Enter telnet localhost port_number Then, enter window scale some_fractional_size See the picture for examples of those commands in action. Pretty cool.  

READ MORE »
Titanium

Tweets

  • Could not connect to Twitter

Recent Posts

  • Breakpoint debugging an Alloy app
  • Titanium graphs with a WebView
  • See the Mac Console for full error details
  • Split window editing in TiStudio
  • Delete a member of an array

EvoLve Pro theme by Theme4Press  •  Powered by WordPress Skypanther Studios
Empowering a mobile world