Skip to content

Instantly share code, notes, and snippets.

View tonylukasavage's full-sized avatar
💭
Learning to make games

Tony Lukasavage tonylukasavage

💭
Learning to make games
View GitHub Profile
module.exports = Alloy.getController('BaseController').extend({
customFunction: function(){ alert('inherited function call!'); }
});
var win = Ti.UI.createWindow({
backgroundColor: "#fff",
fullscreen: false
});
win.addEventListener('open', function(e) {
win.add(Ti.Map.createView());
});

Underscore prefix indicates that the function is created and performed by Alloy. All non-Alloy functions below will be optional;

  • __init - Establish $ as this
  • prelayout - Before any UI is created. Good time to update Alloy.CFG with runtime values for use in styles.
  • __layout - All UI elements are created and added to the view hierarchy
  • postLayout - Everything is prepared, this is where the bulk of the code will go and where beginners will spend all their time.
@tonylukasavage
tonylukasavage / alloybp.sublime-snippet
Created August 10, 2012 01:53
Sublime Text 2 snippet for Titanium Alloy controller boilerplate
<snippet>
<content><![CDATA[
function onReady(args) {
$0
}
module.exports = Alloy.getController('BaseController').extend({
onReady: onReady
});
]]></content>
@tonylukasavage
tonylukasavage / index.xml
Created August 13, 2012 19:05
Alloy <Include>
<Alloy>
<Window>
<Button/>
<Include src="viewInclude"/>
</Window>
</Alloy>
@tonylukasavage
tonylukasavage / index.js
Created August 13, 2012 19:26
Alloy <Require>
function onReady(args) {
$.theView.myImage.image = "/someImage.png";
}
module.exports = Alloy.getController('BaseController').extend({
onReady: onReady
});
@tonylukasavage
tonylukasavage / index_describe.js
Created August 13, 2012 19:46
New controller syntax
// module.exports defines the class for this controller. Most importantly, we can define a base controller
// from which we can inherit. In most cases developers will just use the boilerplate 'BaseController',
// but advanced developer can create their own super and sub classes to enhance code reuse.
module.exports = Alloy.getController('baseController').extend({
// Lifecycle function that is executed before the UI is created or the view hierarchy is established.
// For this reason, the $ variable will not yet have access to the IDed elements from markup. This is
// a good place to make runtime checks and modifications to styles.
onInit: function(args){},
@tonylukasavage
tonylukasavage / file.diff
Created August 15, 2012 16:31
tiapp.xml diff
index 141d489..475eea9 100644
--- a/tiapp.xml
+++ b/tiapp.xml
@@ -1,4 +1,5 @@
-<?xml version="1.0" encoding="UTF-8"?><ti:app xmlns:ti="http://ti.appcelerator.org">
+<?xml version="1.0" encoding="UTF-8"?>
+<ti:app xmlns:ti="http://ti.appcelerator.org">
<deployment-targets>
<target device="mobileweb">true</target>
<target device="iphone">true</target>
var Alloy = require('alloy'),
Backbone = Alloy.Backbone,
_ = Alloy._,
A$ = Alloy.A;
function Controller() {
require('alloy/controllers/<%= parentController %>').call(this);
var exports = <%= exportsObj %>;
// exportsObj looks something like this:
@tonylukasavage
tonylukasavage / app.tss
Created August 16, 2012 16:28
Revised Alloy controller format
"Window": {
backgroundColor: '#fff'
},
"Label": {
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: "#000",
font: {
fontSize: '32dp'
}