<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ActionScript &#8211; Software, Fitness, and Gaming &#8211; Jesse Warden</title>
	<atom:link href="https://jessewarden.com/category/actionscript/feed" rel="self" type="application/rss+xml" />
	<link>https://jessewarden.com</link>
	<description>Software &#124; Fitness &#124; Gaming</description>
	<lastBuildDate>Tue, 08 Feb 2011 18:06:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://jessewarden.com/wp-content/uploads/2016/08/cropped-Lambda2-32x32.png</url>
	<title>ActionScript &#8211; Software, Fitness, and Gaming &#8211; Jesse Warden</title>
	<link>https://jessewarden.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Lua for ActionScript Developers: Crash Course</title>
		<link>https://jessewarden.com/2011/01/lua-for-actionscript-developers.html</link>
					<comments>https://jessewarden.com/2011/01/lua-for-actionscript-developers.html#comments</comments>
		
		<dc:creator><![CDATA[JesterXL]]></dc:creator>
		<pubDate>Tue, 25 Jan 2011 17:43:51 +0000</pubDate>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[corona]]></category>
		<category><![CDATA[lua]]></category>
		<category><![CDATA[programming]]></category>
		<guid isPermaLink="false">http://jessewarden.com/?p=2589</guid>

					<description><![CDATA[Skip Intro Preface I needed a break from Flex for mobile, and wanted to see if there were any other good application frameworks that allowed you to deploy to multiple devices beyond Adobe AIR. Tony Lukasavage had written about a few recently, and Matt Guest had written about his quick experience using Corona for games [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a href="http://jessewarden.com/2011/01/lua-for-actionscript-developers.html#zedispensergoeshere">Skip Intro</a></p>
<p><strong>Preface</strong></p>
<p>I needed a break from Flex for mobile, and wanted to see if there were any other good application frameworks that allowed you to deploy to multiple devices beyond Adobe AIR.  Tony Lukasavage had <a href="http://savagelook.com/blog/portfolio/appcelerator-vs-phonegap-vs-adobe-air">written about a few recently</a>, and Matt Guest had written about his q<a href="http://mattguest.com/2011/01/playing-with-corona/">uick experience</a> using Corona for games based on the <a href="http://news.yahoo.com/video/us-15749625/tween-tech-prodigy-23867645">buzz</a> around <a href="http://naygames.com/">Robert Nay</a>, the 14 year old who knocked Angry Birds out of the top mobile game slot via <a href="http://blog.anscamobile.com/2011/01/bubble-ball-and-corona-sdk-in-the-news/">Bubble Ball</a>.</p>
<p><span id="more-2589"></span>While <a href="http://unity3d.com/">Unity</a> has the best language on the planet, C#, I needed a break from lower level languages. Â In the past, <a href="http://rubyonrails.org/">Ruby</a> and <a href="http://www.djangoproject.com/">Python</a> were greatÂ reprievesÂ for doing smaller projects. Â In doing some mobile apps, I&#8217;ve noticed that for the scope of the project, sometimes 3 weeks or less, the verbose language actually gets in the way. Â So, I was looking for a higher level language, and <a href="http://www.lua.org/pil/index.html">Lua</a> in <a href="http://www.anscamobile.com/corona/">Corona</a> SEEMS to fit the bill, but I&#8217;m still learning. Â I liked how I could save a file in <a href="http://macromates.com/">TextMate</a> and and it would just refresh the iPhone/Android emulator. HOTNESS! Uber fast compared to mxmlc and &#8220;Building&#8230;&#8221; in Flash Builder, even when using pure AS3. Â The interpreted nature of Lua helps speed that up (I guess).</p>
<p><strong>Introduction</strong></p>
<p>I&#8217;ve only been reading up on Lua for 1 day, but here&#8217;s a quick crash course to get traditional ActionScript programmers up to speed with Lua concepts. Â If you&#8217;ve done any ActionScript 1, or even JavaScript, you&#8217;ll find this very familiar to traditional ECMA concepts. Â If you&#8217;re a Java/C guy coming to Flex and now reading this, it may be a little weird.</p>
<p>I&#8217;m still learning the OOP &amp; packages Lua stuff, so will post that in a later article. Â In reading the docs, it&#8217;s pretty clear OOP and packages aren&#8217;t really something the original language designers figured you&#8217;d actually do, so it seems like a ton of work, more than it took in AS1, to get inheritance and packages.</p>
<p><strong>WARNING</strong>: This guide was written primarely to help me learn Lua and have all the common comparisons on one page. Â I&#8217;m sure it has errors and misconceptions; if I get railed in the comments, I&#8217;ll update this post as soon as possible. Â Here there be dragons, bitches!</p>
<p><a name="zedispensergoeshere"></a><strong>Getting Started</strong></p>
<p>If you&#8217;re on a Mac, the best thing to do is go download &amp; install <a href="http://www.anscamobile.com/corona/">Corona</a> + <a href="http://macromates.com/">TextMate</a>, and then install the <a href="http://www.ludicroussoftware.com/corona/corona-bundle-for-textmate/">Corona Bundle for TextMate</a>. Â For Windows users, you can <a href="http://blog.anscamobile.com/2011/01/corona-sdk-is-now-on-windows/">check out more</a> on their blog.</p>
<p><strong>Output</strong></p>
<p>To show output from your code in ActionScript for the Flash IDE&#8217;s console, or Flash Builder&#8217;s console, you use trace:</p>
<pre lang="actionscript">trace("Hello World!");</pre>
<p>In Lua, you use print:</p>
<pre lang="lua">print("Hello World!")</pre>
<p>You&#8217;ll notice there is no semi-colon used in Lua.  Like ActionScript they are optional, but most code I&#8217;ve seen doesn&#8217;t use them.  I&#8217;ve only met 1 ActionScript coder that didn&#8217;t use semi-colons.</p>
<p>There are also no brackets {} in Lua, similar to Python, although the whitespace isn&#8217;t as strict.</p>
<p><strong>Comments</strong></p>
<p>In ActionScript, a single line comment is //:</p>
<pre lang="actionscript">// This is a comment ActionScript</pre>
<p>In Lua, a single line comment is: &#8212;</p>
<pre lang="lua">-- This is a comment in Lua</pre>
<p>A multi-line comment in ActionScript starts with /* and ends with */:</p>
<pre lang="actionscript">/*
This is a
multiline comment
in ActionScript
*/</pre>
<p>In Lua, it starts with &#8211;[[ and ends up ]]&#8211;:</p>
<pre lang="lua">--[[
This is a
multiline comment
in Lua
]]--</pre>
<p><strong>Variables</strong></p>
<p>In ActionScript 1, this was a global variable:</p>
<pre lang="actionscript">_global.foo = "bar";</pre>
<p>In Lua, this is a global variable:</p>
<pre lang="lua">foo = "bar"</pre>
<p>In ActionScript 3, you usually have to utilize the Singleton design pattern or a default namespace class to get globals:</p>
<pre lang="actionscript">package
{

	public class MyGlobals
	{

		public var foo:String;

		private static var _inst:MyGlobals;

		public function get instance():MyGlobals
		{
			if(_inst == null)
				_inst = new MyGlobals();

			return _inst;
		}
	}
}

// then to use
MyGlobals.instance.foo = "bar";</pre>
<p>&#8230;or a public static variable on MyGlobals:</p>
<pre lang="actionscript">package
{
	public class MyGlobals
	{
		public static var foo:String;
	}
}

// then to use
MyGlobals.foo = "bar";</pre>
<p>In ActionScript 3, un-initialized variables on non-dynamic objects such as classes such as Strings or other by reference variables are null:</p>
<pre lang="actionscript">trace(foo); // null
foo = "bar";
trace(foo); // bar</pre>
<p>Lua uses nil:</p>
<pre lang="lua">print(foo) --> nil
foo = "bar"
print(foo) --> bar</pre>
<p>To remove a reference on a strongly-typed object in ActionScript 3, you set the variable to null:</p>
<pre lang="actionscript">myArray = [1, 2, 3];
myArray = null;</pre>
<p>In Lua, you set it to nil:</p>
<pre lang="lua">myNumber = 10
myNumber = nil</pre>
<p>Notice I used a Number in Lua.  In ActionScript 1, you could do that since all were variants, but in AS3, you can&#8217;t set a Number to null, only another Number or NaN.</p>
<p>Lua (I think) has it&#8217;s own garbage collection like ActionScript 1 and 3 do, thus they both use null and nil to decrement the reference count on objects.  Both have similar rules for immutable primitives, like String and Number always creating new variables, and this copying by value when you create new ones:</p>
<pre lang="actionscript">var a:String = "moo";
var b:String = a;
a = "whoa";
trace(a); // whoa
trace(b); // moo</pre>
<p>Lua is the same way.</p>
<p>The reverse is true for Objects that use by ref such as Arrays/Lists and other Objects.</p>
<pre lang="actionscript">var a:Array = [1, 2, 3];
var b:Array = a;
a.pop();
trace(a); // 1,2
trace(b); // 1,2
trace(a == b); // true</pre>
<p>So, while ActionScript 3 has certain rules for primitives such as String, Number, int, and uint, in Lua you can just set it&#8217;s String and Number (it only has Float) to nil.</p>
<p><strong>Types</strong></p>
<p>In ActionScript 1, most everything was a variant.  In ActionScript 3, we have a true type system.  In Lua, everything is basically a variant.  In AS1, if you wanted to figure out the type of something, you&#8217;d use typeof:</p>
<pre lang="actionscript">var foo = "bar";
trace(typeof(foo)); // bar
var foo = 10;
trace(typeof(foo)); // number
trace(typeof(typeof)); // function</pre>
<p>In Lua, you use type:</p>
<pre lang="lua">foo = "bar"
print(type(foo)) --> string
foo = 10
print(type(foo)) --> number
print(type(type)) --> function</pre>
<p><strong>Booleans &amp; if tests</strong></p>
<p>Keep in mind, nil and false always equate to false. Everything else is true. The use of 0 and &#8220;&#8221; are considered true in Lua, and in ActionScript.  Sometimes people will use if in ActionScript to test for true or if a variable is not null:</p>
<pre lang="actionscript">if(foo)
{
  trace("foo is: " + foo); // bar
}
else
{
   trace("foo is null.");
}</pre>
<p>Similar in Lua:</p>
<pre lang="actionscript">if foo then
	print("foo is: " .. foo)
else
	print("foo is nill")
end</pre>
<p><strong>Concatenation</strong></p>
<p>Notice in ActionScript, + is used for concatenating everything in trace, and ActionScript is smart enough to coerce and/or call toString() on certain Objects.</p>
<pre lang="actionscript">trace("foo " + "bar"); // foo bar</pre>
<p>In Lua, you use ..</p>
<pre lang="lua">print("foo " .. "bar") --> foo bar</pre>
<p><strong>Numbers/Floats</strong></p>
<p>Numbers in Lua are similar to Numbers in ActionScript 1; they are floats (decimals).  There are no ints or uints.</p>
<p><strong>Tables vs Objects</strong></p>
<p>Tables are the what Lua calls Objects.  They have nearly the exact same syntax, although their constructors are completely different and have a ton of syntactic sugar in Lua.  They&#8217;re basically associative arrays.  You can use any value as the key in Lua, excluding nil.</p>
<pre lang="actionscript">var a:Object = {};
var k:String = "x";
a[k] = 10;
trace(a["x"]); // 10
trace(a.x); // 10</pre>
<pre lang="lua">a = {}
k = "x"
a[k] = 10
print(a["x"]) --> 10
print(a.x) --> 10</pre>
<p>To remove slots in ActionScript, you use delete:</p>
<pre lang="actionscript">delete a.x;</pre>
<p>In Lua, you just set it to nil:</p>
<pre lang="lua">a.x = nil</pre>
<p><strong>Math</strong></p>
<p>Math operations are about the same using +, -, *, / and standard math precedence/order of operations including parentheses ()&#8230; sort of. You can <a href="http://www.lua.org/pil/3.5.html">see the precedence in the docs</a>.</p>
<p><strong>Relational Operators</strong></p>
<p>Lua has about the same operators as ActionScirpt excluding &#8220;not equal&#8221;.</p>
<pre lang="actionscript"> <   >   <=  >=  ==  !=</pre>
<pre lang="lua"> <   >   <=  >=  ==  ~=</pre>
<p>Notice the last one.</p>
<p><strong>Logical Operators</strong></p>
<p>ActionScript has:</p>
<pre lang="actionscript">&& // and
|| // or
!= // Borat says, "NNNooott!"</pre>
<p>Lua has:</p>
<pre lang="lua">and --> and
or --> or
not --> not</pre>
<p>So, from the Lua docs, here&#8217;s ActionScript:</p>
<pre lang="actionscript">trace(4 && 5);         // 5
trace(null && 13);         // null
trace(false && 13);         // false
trace(4 || 5);         // 4
trace(false || 5);         // 5</pre>
<p>And Lua:</p>
<pre lang="lua">print(4 and 5)         --> 5
print(nil and 13)      --> nil
print(false and 13)    --> false
print(4 or 5)          --> 4
print(false or 5)      --> 5</pre>
<p><strong>Assignments and Statements</strong></p>
<p>ActionScript and Lua have a similiar syntax for statements although ActionScript has more helper shortcuts like +=, ++, etc.</p>
<pre lang="actionscript">var a:Number = 1;
a = a + 1;
trace(a); // 2
a++;
trace(a); // 3</pre>
<pre lang="lua">a = 1
a = a + 1
print(a) // 2
a = a + 1
print(a) // 3</pre>
<p>You can also do single line with multiple variables; while un-readable to me, it actually comes into play when you have functions returning multiple values and error handling as you&#8217;ll see later.</p>
<pre lang="lua">a, b = 10, 2*x</pre>
<p>For example, assuming getResults() returns 2 values instead of the standard 1 in ActionScript, you can get the first and second via:</p>
<pre lang="lua">a, b = getResults()</pre>
<p>Yes, craziness.</p>
<p><strong>Local Variables</strong></p>
<p>Local variables in ActionScript:</p>
<pre lang="actionscript">var i:Number = 0;

function foo()
{
   trace(i); // 0
   var i:Number = 23;
   trace(i); // 23
}</pre>
<p>And in Lua:</p>
<pre lang="lua">i = 0
local i = 1</pre>
<p>Local variables are stricter in scope in Lua than in ActionScript.  They are similar to how they are (I think) in C, where it&#8217;s &#8220;block based&#8221;.  In ActionScript, the local variable is local to the entire function whereas in Lua, it&#8217;s local only to the current block it&#8217;s in, such as the then/else part of the if then statement.  Finally, in both languages, local variables are faster to access.</p>
<p>An example of local scope in Lua is a while loop:</p>
<pre lang="lua">x = 10
local i = 1 --> local to chunk
while i < 2 do
   local x = i * 2 -- local to the while body   
   print(x) --> 2, 4, 6, 8, ...
   i = i + 1
end</pre>
<p>The locals, like in ActionScript, aren&#8217;t actually created until you initialize them, so this makes for more efficient code.</p>
<p><strong>Control Structures</strong></p>
<p>Lua has the standard <strong>if</strong>, <strong>while</strong>, <strong>for</strong>, and <strong>repeat</strong> statements.  The difference is the <strong>if</strong>, <strong>while</strong>, and <strong>for</strong> need a corresponding <strong>end</strong> for the statement.  The <strong>repeats</strong> use an <strong>until</strong> statement.</p>
<p>Here&#8217;s a simple if statement in ActionScript:</p>
<pre lang="actionscript">if(a < 0)
{
   a = 0;
}</pre>
<p>And Lua:</p>
<pre lang="lua">if a < 0 then a = 0 end</pre>
<p>... or:</p>
<pre lang="lua">if a < 0 then
   a = 0
end</pre>
<p>Here's an if else statement in ActionScript:</p>
<pre lang="actionscript">if(a < b)
{
   return a;
}
else
{
   return b;
}</pre>
<p>And in Lua:</p>
<pre lang="lua">if a < b then
   return a
else
   return b
end</pre>
<p>...that too can be written on one line.</p>
<p>Like Python, Lua has elseif:</p>
<pre lang="lua">if value == "north" then
   return y  - 1
elseif value == "south" then
   return y + 1
elseif value == "east" then
   return x + 1
elseif value == "west" then
   return x - 1
else
   error("invalid direction, yo!")
end</pre>
<p>Notice we have the standard == to test for equality.  The common way to report errors is the error function; we'll get to him in a bit.</p>
<p><strong>Loops</strong></p>
<p>A quick note about loops.  In ActionScript, the first index of an Array or Vector is 0.  In Lua, it's whatever you want, but the convention is 1.  You can use 0 if you really want to, but a lot of the existing libraries may not work since they follow the 1 convention.  Also there isn't a concept of "Array.length" in Lua.  The first item found that has nil is considered to be "end" of the Array/List/Table.</p>
<p><strong>While Loop (and Arrays)</strong></p>
<p>For you while fans, here's one in ActionScript:</p>
<pre lang="actionscript">var i:int = 0;
while(list[i])
{
   trace(list[i]);
   i++;
}</pre>
<p>And in Lua:</p>
<pre lang="lua">local i = 1
while list[i] do
   print(list[i])
   i = i + 1
end</pre>
<p>Notice Lua starts with 1 whereas ActionScript starts with 0.  Also notice the while loop in Lua is testing if list[i] is not equal to false or nil.  The way Arrays (in this case a simple table acting as an associative array) work for most looping operations is you test for nil in them.  If it finds nil, it assumes it is the end of the array/list.</p>
<p><strong>For - 2 Types</strong></p>
<p>There are 2 types of for loops.  For loops are similar to ActionScript, but the syntax is quite different.  Sometimes smaller loops are written on 1 line.  You'll constantly see this in Lua because of it's Functional bent, a lot of people try to write as terse as syntax as possible.  If you come from a Java/ActionScript 3 only background, you'll want to spread it out more.  I'll do both below.</p>
<p>Lua's numeric version of for loop works in pseudo code like this:</p>
<pre lang="lua">for var=start,end,optionalIncrement do
   something
end</pre>
<p>You don't need to include the increment; if you don't, it'll assume 1.  Most for loops I've seen in ActionScript always use 1 anyway.</p>
<p>Here's how we loop through 1 to 10 in ActionScript:</p>
<pre lang="actionscript">for(var i:int=1; i < 11; i++)
{
   trace(i);
}</pre>
<p>Here's how we do the same in Lua:</p>
<pre lang="lua">for i=1,10,1 do print(i) end</pre>
<p>...or:</p>
<pre lang="lua">for i=1,10 do print(i) end</pre>
<p>...or even:</p>
<pre lang="lua">for i=1,10,1 do
   print(i)
end</pre>
<p>There are some strange things too.  The var, or i in this case, is a local variable to the for loop.  After the loop is done in ActionScript, you can reference it, but not in Lua.</p>
<p>Also, functions/expressions in the for loop itself for start/end/increment are only run once where as in ActionScript, the test &amp; increment are done each loop.</p>
<p>Like ActionScript, if you want to abort the mofo, use break.  If you want to break it down, use <a href="http://soundcloud.com/dj-icey">DJ Icey</a>.</p>
<p>The generic for is like a for var n or a for each in ActionScript where you iterate over properties of an Object.  This gets pretty deep in Lua, and they have a TON of different ways one can write iterators, using closures, coroutines, etc.  I encourage you to briefly <a href="http://www.lua.org/pil/4.3.5.html">read the docs on generic for</a> and hit the <a href="http://www.lua.org/pil/7.html">advanced stuff</a> (advanced for me, heh) if you're into that kind of thing (*cough* Python developers *cough*).</p>
<p><strong>Break and Return Placement</strong></p>
<p>While break and return are similar to ActionScript, their placement is more strict.  Both have to be right before the last part of a block (right above end, else, or until).</p>
<p><strong>Functions</strong></p>
<p>Functions in Lua are just like they are in ActionScript with some subtle rules about usage you can <a href="http://www.lua.org/pil/5.html">read more on</a>.  What I want to focus on is multiple return values which plays into how you do error handling/logging in Lua if you come from a Flash background.</p>
<p>It's called unconventional in the docs, but when all functions that run in protected mode (more on that later), return errors as the 2nd parameter, that's not unconventional, that's conventional.</p>
<p>Anyway, check out how the find string function looks in Lua:</p>
<pre lang="lua"> s, e = string.find("hello Lua users", "Lua")
print(s, e)   -->  7      9</pre>
<p>The find gets the first index where it occurs and ends or nil if it can't find it.  Notice how the first result is in s, and the second is in e.  To do this yourself, you just return 2 values like so:</p>
<pre lang="lua">function fooByTwo()
   return 1, 2
end

uno, dos = fooByTwo()</pre>
<p><strong>Variable Number of Arguments</strong></p>
<p>Lua has rest parameters like ActionScript has as well:</p>
<pre lang="lua">function showNames (...)
   for i, name in ipairs(arg) do
      print(i .. ":name=" .. name .. "\t")
   end
end</pre>
<p>Notice the <strong>arg</strong> variable is a predefined variable in functions, much like <strong>arguments</strong> was in ActionScript 1.  In ActionScript 3, we can name it whatever we want:</p>
<pre lang="actionscript">function showNames(... names)</pre>
<p>Finally, you'll notice <strong>ipairs</strong> is used a lot as a sort of default iterator for loops.</p>
<p><strong>Function Scope</strong></p>
<p>You can read more about lexical scoping, closures, and all the other Functional stuff if you want, but I wanted to focus on Scope because it's bloody AS1's thisThing.owner/mx.utils.Delegate all over again.  If you don't remember what I'm talking about, or you have no context, <a href="http://www.bit-101.com/blog/?p=525">Keith talks about it</a> and how to get around ActionScript 1's scoping challenges via the Activation Object and Mike Chambers elaborates on how <a href="http://www.mikechambers.com/blog/2008/10/08/function-closures-and-this-in-actionscript-3/">closures work in AS3</a>.</p>
<p>Before AS3, classes had their callbacks scoped to what object they were called from, not where they were defined; thus you had to give child objects pointers back to their parent classes.</p>
<p>Lua has the same deal with functions.  I'll elaborate more in a future OOP article since I'm still learning, but here's how it works.  Functions in Lua by default don't have a <strong>this</strong> or <strong>self</strong>.  Much like Python, you have to pass in scope in a generalized fashion.</p>
<p><strong>Static</strong></p>
<p>So... here's how you do a static method(sort of) in ActionScript:</p>
<pre lang="actionscript">package
{
	public class Bar
	{
		public static function foo(a:String):void
		{
			trace("passed in var: " + a);
		}
	}
}

Bar.foo();</pre>
<p>...and in Lua:</p>
<pre lang="lua">Bar = {}
function Bar.foo(a)
   print("passed in var: " .. a)
end
Bar.foo("Cow")</pre>
<p>In Lua, like AS1, you delete your class objects, however, thus if I made an instance, and tried to call it, it'd cause an error:</p>
<pre lang="lua">b = Bar
Bar = nil
b.foo("Test") --> Error</pre>
<p><strong>Instance Methods</strong></p>
<p>So how do we get "this" equivalent?  In 2 ways; it depends on how you call the function.  Remember, Functional people like carrying scope around like a magic gem... seems like a lot of work to me, but I grew into an OOP world so what do I know.</p>
<p>You'd refine the above to this:</p>
<pre lang="lua">function Bar.foo(self, a)
   print("passed in var: " .. a)
end</pre>
<p>Then, you can call it in 2 ways, the first manual way:</p>
<pre lang="lua">b = Bar;
b.foo(b, "test")</pre>
<p>Or the built-in way they have to do that for you:</p>
<pre lang="lua">b = Bar;
b:foo("test")</pre>
<p>Notice the colon instead of the dot.</p>
<p>If you remember Object.prototype in ActionScript 1 where you had to manually add this inside all functions, it's very similar.</p>
<p><strong>Classes</strong></p>
<p>I'll get into classes and packages later... they are whack compared to what I'm used too.  For now, here's 3 syntax variations you can do (this'll look familiar to you AS1 devs):</p>
<p>The object/table way:</p>
<pre lang="lua">Lib = {}
Lib.foo = function (x,y) return x + y end
Lib.goo = function (x,y) return x - y end</pre>
<p>Using the Lua table constructor way:</p>
<pre lang="lua">Lib = {
  foo = function (x,y) return x + y end,
  goo = function (x,y) return x - y end
}</pre>
<p>And the common way I've seen in Cornoa (I think):</p>
<pre lang="lua">Lib = {}
function Lib.foo (x,y)
   return x + y
end
function Lib.goo (x,y)
   return x - y
end</pre>
<p><strong>Errors</strong></p>
<p>Lua's runtime, at least from what I've seen in Corona, runs just like Flash Player 8 on down did.  If the original AVM has an error, it aborts the current function and/or related stack items, and tries its best to proceed.  You can run Lua where it'll output to the console (Terminal if on Mac), but you won't see the errors in your code unless you specifically trap/log them.</p>
<p>A common error check in ActionScript 3 is checking for null; since this is the one thing our mxmlc compiler (and the Flash IDE) isn't really good at finding since Flash often gets external data in it, and thus "garbage in, garbage out" comes into play.</p>
<pre lang="actionscript">if(UserFactory.getUser(xml) == null)
{
   throw new Error("Dude, our XML is whack, yo! ...or maybe our parsing code is lame.");
}</pre>
<p>Lua can do something similar:</p>
<pre lang="lua">if not UserFactory.getUser(xml) then error("Dude, our XML is whack, yo! ...or maybe our parsing code is lame.") end</pre>
<p>However, that's a pretty common operation in Lua, thus they have an <strong>assert</strong> function.  If assert gets a false or nil back from the function, it'll raise an error with the string you pass in the 2nd parameter:</p>
<pre lang="lua">user = assert(UserFactory.getUser(xml), "Failed to parse user."),</pre>
<p>If you don't raise your own error in functions, Lua will return <strong>nil</strong> by default.  Otherwise, you can call the built in <strong>error</strong> function, passing in the reason for the failure as a string, simliar to throw new Error("<a href="http://www.youtube.com/watch?v=30BvoBbrTxM">that blowed up real good</a>") in ActionScript 3.  You'll be able to see this in the console/Terminal.</p>
<p>Thus, the common way to play it safe is to use <strong>assert</strong>.  Remember before explaining how Functions can return 2 values, and by default will return the error, if any, as the 2nd parameter?  This works naturally with assert (example below from <a href="http://www.lua.org/pil/8.3.html">the docs</a>):</p>
<pre lang="lua">file = assert(io.open("no-file", "r"))
      --> stdin:1: no-file: No such file or directory</pre>
<p>Notice you didn't have to write a 2nd parameter in the error function, it'll return and print automatically via assert.</p>
<p><strong>Custom Error Handling</strong></p>
<p>Lua has a try/catch equivalent as well.  If you call error("Explosions") inside a Lua function, it can be caught via <strong>pcall</strong> which means "protected call".  Using pcall, it'll return true if all is well, and false if an error occurred.  In ActionScript, you'd go:</p>
<pre lang="actionscript">public function foo():void
{
	if(!allGoodInDaHoodDogwood)
	{
		throw new Error("ZOMG, Compton!");
	}
	else
	{
		return;
	}
}

try
{
	foo();
}
catch(err:Error)
{
	trace(err);
}</pre>
<p>In Lua:</p>
<pre lang="lua">function foo()
	if not allGoodInDaHoodDogwood then
		error("ZOMG, Compton!")
	else
		return
	end
end

if pcall(foo) then
	-- no errors in foo
	print "They SHOOTIN'!!!... aw made you look, you slave to a page in my rhyme book."
else
	-- foo threw an error
	print "foo blew up"
end</pre>
<p><strong>Stacktrace</strong></p>
<p>You can use</p>
<pre lang="lua">print(debug.traceback)</pre>
<p>to see the stacktrace up to the point of execution.</p>
<p><strong>Conclusion</strong></p>
<p>As we can see, Lua has a lot in common with ActionScript, specifically ActionScript 1, JavaScript, and ECMA in general.  There is much more to Lua than the above, and the above is just from 1 day of reading &amp; playing.  If you're not looking to totally rock your world when learning a new language, say <a href="http://jessewarden.com/2010/04/cocoa-chronicles-1-actionscript-vs-objective-c.html">ActionScript to Objective C</a>, then I encourage you to check out Lua, specifically using the Corona resources I stated at the top of this article.  When I figure this OOP and package stuff out, I'll write a follow up post.</p>
<p>Please feel free to post corrections in the comments; I'm obviously still new at Lua.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://jessewarden.com/2011/01/lua-for-actionscript-developers.html/feed</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
			</item>
		<item>
		<title>JSFL Script to Ensure Actual ActionScript Classes Exist for Symbols</title>
		<link>https://jessewarden.com/2010/12/jsfl-script-to-ensure-actual-actionscript-classes-exist-for-symbols.html</link>
					<comments>https://jessewarden.com/2010/12/jsfl-script-to-ensure-actual-actionscript-classes-exist-for-symbols.html#comments</comments>
		
		<dc:creator><![CDATA[JesterXL]]></dc:creator>
		<pubDate>Tue, 28 Dec 2010 18:50:26 +0000</pubDate>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[cs3]]></category>
		<category><![CDATA[cs4]]></category>
		<category><![CDATA[cs5]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jsfl]]></category>
		<guid isPermaLink="false">http://jessewarden.com/?p=2577</guid>

					<description><![CDATA[One way to design or skin ActionScript 3 projects is using the Flash IDE for graphical assets. Â You export your FLA as an SWC, and you can utilize those assets in your AS3 and/or Flex project. Â Flash CS3/CS4/CS5 have the ability to link to an ActionScript 3 class that represents the code behind the Symbol. [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>One way to design or skin ActionScript 3 projects is using the <a href="http://adobe.com/products/flash/">Flash</a> IDE for graphical assets. Â You export your FLA as an SWC, and you can utilize those assets in your AS3 and/or Flex project. Â Flash CS3/CS4/CS5 have the ability to link to an ActionScript 3 class that represents the code behind the Symbol. Â If the Flash IDE doesn&#8217;t find the class in its source paths, it&#8217;ll create one for you.</p>
<p>The downside is, when you compile, you do not get errors if the Flash IDE didn&#8217;t find a class for a particular Symbol that&#8217;s set to have one. Â Maybe you mis-typed the package path or class name. Â Maybe you forgot to set the class path for the FLA. Â Maybe the FLA is in the wrong place. Â Whatever the reason, your code &#8220;won&#8217;t work&#8221; and you won&#8217;t know why. Â You may not get code hints in <a href="http://www.adobe.com/products/flashbuilder/">Flash Builder</a> / <a href="http://www.fdt.powerflasher.com/">FDT</a> / <a href="http://www.jetbrains.com/idea/">IntelliJ</a>, and certain other dependencies may be missing as well and you&#8217;ll be left wondering why.</p>
<p><span id="more-2577"></span><a href="http://jessewarden.com/archives/blogentryimages/check-class.jpg"><img decoding="async" style="padding-right: 4px; padding-bottom: 4px; width: 240px;" src="http://jessewarden.com/archives/blogentryimages/check-class.jpg" alt="Flash CS5 Check Class" width="240" align="left" /></a>The Flash IDE provides a check mark button next to the linkage class to allow you to confirm or deny Flash can find the class. Â In a quick scan of the <a href="http://help.adobe.com/en_US/flash/cs/extend/index.html">JavaScript for Flash docs</a>, I could not find a way to use this button&#8217;s functionality in JSFL. Â So, I wrote a quick script that does.</p>
<p><strong>NOTE</strong>: I do not take source paths into account; I assume that the classes are in the same directory as the FLA&#8217;s. Â You can easily change this by querying <a href="http://help.adobe.com/en_US/flash/cs/extend/WS5A00B146-30BC-4841-A27F-325968E8084B.html">fl.getDocumentDOM().sourcePath</a>, or just hardcoding your known path.</p>
<pre lang="Javascript">fl.outputPanel.clear();
fl.trace("*** Checking for un-found classes... ***");
var totalNotFound = 0;

var doc = fl.getDocumentDOM();
var lib = doc.library;
var items = lib.items;

var itemsLen = items.length;

for(var i = 0; i &lt; itemsLen; i++)
{

	var item = items[i];
	/*
	fl.trace("--------------");
	for(var prop in item)
	{
		fl.trace(prop + "::" + item[prop]);
	}
	*/

	if(item.linkageExportForAS)
	{
		var className = item.linkageClassName;
		var classPath = className.split(".").join("/");
		var exists = doesClassExistOnDisk(classPath);
		if(exists == false)
		{
			totalNotFound++;
			fl.trace("Couldn't find class for '" + item.name + "', class: " + className);
		}
	}

}

if(totalNotFound == 0)
{
	fl.trace("*** DONE. All classes found.");
}
else
{
	fl.trace("*** DONE. " + totalNotFound + " classes not found.");
}

function doesClassExistOnDisk(classPath)
{
	var filename = classPath + ".as";
	var doc = fl.getDocumentDOM();
	var currentFolder = doc.pathURI.split(doc.name).join("");
	var fullURI = currentFolder + filename;
	//fl.trace("fullURI: " + fullURI);
	return FLfile.exists(fullURI);
}</pre>
<p>On a side note, <a href="http://summitprojectsflashblog.wordpress.com/">Dru Kepple has a lot of wonderful JSFL classes</a> to help working with ActionScript in the Flash IDE, specifically <a href="http://summitprojectsflashblog.wordpress.com/2010/11/29/jsfl-get-notifications-on-a-bad-document-class/">the Document class.</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://jessewarden.com/2010/12/jsfl-script-to-ensure-actual-actionscript-classes-exist-for-symbols.html/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Adobe, Please Bring Flash Builder Up To Par</title>
		<link>https://jessewarden.com/2010/09/adobe-please-bring-flash-builder-up-to-par.html</link>
					<comments>https://jessewarden.com/2010/09/adobe-please-bring-flash-builder-up-to-par.html#comments</comments>
		
		<dc:creator><![CDATA[JesterXL]]></dc:creator>
		<pubDate>Wed, 08 Sep 2010 17:42:49 +0000</pubDate>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[fdt]]></category>
		<category><![CDATA[flashdevelop]]></category>
		<category><![CDATA[ide]]></category>
		<category><![CDATA[intellij]]></category>
		<category><![CDATA[visualstudio]]></category>
		<guid isPermaLink="false">http://jessewarden.com/?p=2442</guid>

					<description><![CDATA[This post is long overdue, and I want to personally apologize to Adobe for taking so long to post it. Adobe (Macromedia?) thrives on customer feedback, early, and makes a serious effort to prioritize on it whilst comparing to their own market research data they do by proactively reaching out. I haven&#8217;t done this in [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>This post is long overdue, and I want to personally apologize to Adobe for taking so long to post it.  Adobe (Macromedia?) thrives on customer feedback, early, and makes a serious effort to prioritize on it whilst comparing to their own market research data they do by proactively reaching out.  I haven&#8217;t done this in a long while, focusing on business vs. the actual tools &amp; runtimes.</p>
<p>It&#8217;s long overdue.  <a href="http://www.adobe.com/products/flashbuilder/">Flash Builder 4</a> is a mess, and hopefully fixing/improving the following items will bring it up to par. Â If you are a product engineer, <a href="http://jessewarden.com/2010/09/adobe-please-bring-flash-builder-up-to-par.html#problems">skip the intro</a>.</p>
<p><span id="more-2442"></span><strong>Problem</strong></p>
<p>Flash Builder 4 is a great leap forward from Flex Builder 3. Â It&#8217;s not any large features, but rather a bunch of little, consistent things that lead to a pleasant experience.</p>
<p>Years of neglecting other areas, as well as blatant missing features that open source alternatives &amp;Â competingÂ IDE&#8217;s have makes me question if there is any serious money behind Flash Builder. Â I know the effort and will are there; even after distancing myself from the Adobe product teams the last 3 years, when I do return via email/Twitter, they still have great attitudes, and want to continually improve their tools/runtimes.</p>
<p>Bottom line, I and many others are more productive using open sourceÂ alternativesÂ to Flash Builder, and usually only keep Flash Builder around for 3 key features (Library project linking, Design View, and superior MXML handling, specially with states). Â There are a lot of common workflows that seem to be ignored, and even after 4 years of the community bringing them up, they still aren&#8217;t remedied.</p>
<p>I outline the problems below with potential solutions. Â Some solutions are actually easy; you just copy open source implementations.</p>
<p><strong>Call To Action</strong></p>
<p>I cannot promote Flash Builder 4 to my clients, nor will I spend another dime on Flash Builder 4/5 licenses until Adobe takes Flash Builder seriously by making 5 on par with open source alternatives. Â While I respect that some of the blame lies on the <a href="http://eclipse.org">Eclipse</a> foundation, Adobe clearly thinks there is value there if they base a Designer specific tool&#8217;s future, <a href="http://adobe.com/products/catalyst/">Catalyst</a>, on top of Eclipse&#8217;s architecture.</p>
<p>I, and millions of others sent a message to Adobe with CS4. Â We were sick and tired of incomplete features, bugs, and crashes. Â Adobe then laid of 10% of their staff due to poor CS3 sales&#8230; even though 1 month prior their CEO was on stage at the Adobe MAX conference saying sales were doing well. Â They did this again the following year. Â You can blame it on theÂ recession. Â You can blame it on a public company doing what most do in down times; laying off staff to boost their stock value when dividends are nowhere to be seen because there is no forthcoming company revenue.</p>
<p>&#8230;or you can take responsibility for your bad software, and fix it. Â I was a devoted customer until CS3; we fought with our wallets, and our wallets won. Â  Which sucks. Â My career and life are based on Adobe&#8217;s product line. Â When you, Adobe, suck, life sucks. Â Not just for me, for the world. Â You&#8217;re doing important work.</p>
<p>The following are problems with potential solutions.</p>
<p><a name="problems"></a><strong>1. Code Hints</strong></p>
<p><a href="http://www.flashdevelop.org/wikidocs/index.php?title=Main_Page">Flash Develop</a>, <a href="http://www.fdt.powerflasher.com/">FDT</a>, <a href="http://www.jetbrains.com/idea/">IntelliJ</a>, and <a href="http://www.microsoft.com/visualstudio/en-us/visual-studio-2010-launch?WT.mc_id=SEARCH&amp;WT.srch=1">Visual Studio</a> all give code hints for your classes, methods, and variables WHILE YOU TYPE. Â No period needs to be post-reached, not keyboard command; it just shows you a drop down WHILE YOU TYPE.</p>
<p>Worse, if youÂ misspellÂ something and back up, most of the time the drop down will go away, forcing you to spend more time to get the code hint to come back up&#8230; or just say eff it and code like your in AS1 (or Python).</p>
<p>This should be top priority; I understand if you&#8217;re waiting on Eclipse to add this.</p>
<p><strong>2. Automatic Class Importing</strong></p>
<p>Flash Develop and FDT both auto-import for you while you type and hit enter. Â IntelliJ gives you the option to hit Alt+Enter to import a class of your choice, or perhaps define it which is even cooler. Â Know what Flash Builder does? Â Doesn&#8217;t compile, and blames it on you. Â Gee, thanks $500 IDE. Â I paid you $500 bucks to bitch at me and not auto-import my class you know full well where it is.</p>
<p>My code is littered with var a:SomeClass. Â If you go on a blank line, and type var a, it&#8217;s the quickest way to get the class drop down. Â From there, you can hit enter which&#8217;ll auto import the class. Â You then delete the line.</p>
<p>Half of the problem is that the drop down is just flaky; miss it, and it won&#8217;t import your class. Â Just start typing in a non-start line place, and Flash Builder won&#8217;t even give you a code hint. Â Import yourself.</p>
<p>Please do a better job of auto-importing. Â Level 1 is to get what Flash Develop/FDT do, Level 2 is to match IntelliJ&#8217;s intelligent options.</p>
<p><strong>3. Slow Code Hinting Response &amp; Mispellings</strong></p>
<p>Part<span style="color: #000000;"> of the problem is the code hinting is just slow. Â IntelliJ, which is slower than Eclipse, still seems to consistently work. Â While Flash Builder 4 has significant improvements forÂ misspellingsÂ over Flex Builder 3,Â ESPECIALLYÂ in the class creation dialogue, for the code hints, 9 times outta 10, if you mispell &#8220;Graa&#8221; instead of &#8220;Grap&#8221; for Graphics, good bye dialogue, please start again.</span></p>
<p><span style="color: #000000;">If you can&#8217;t increase the responsiveness, then just be more forgiving with spelling, or just fix #1, and you should be good.</span></p>
<p><span style="color: #000000;"><strong>4. Stop Being ActionScript Racist: ActionScript vs. Flex</strong></span></p>
<p><span style="color: #000000;">You all have been doing this crap since Flash 8. Â Back then, you&#8217;d show AS3 code hints for AS2; even help would show AS3 when I specifically set AS2 in the publish settings. Â Back then, QA wasÂ sincerelyÂ concerned, but it still shipped. Â &#8220;We don&#8217;t want you to use AS2 anyway&#8221;.</span></p>
<p><span style="color: #000000;">When people like <a href="http://www.bit-101.com/blog/">Keith Peters</a>, <a href="http://stevensacks.net">Steven Sacks</a>, <a href="http://gskinner.com/blog">Grant Skinner</a>, and <a href="http://darronschall.com">Darron Schall</a> bitch about it, and you do nothing, that&#8217;s a serious communication problem&#8230; and makes me question if the assholes who used to run Flash Media Server 1 &amp; Flex 1 teams are now running Flash Builder team. Â Aka, &#8220;Screw you, your ideas make us and our shareholders no money, please DIAF.&#8221;</span></p>
<p><span style="color: #000000;">When I create an ActionScript 3 project, and go to import flash.display.Graphics, but you give me a code hint spark.primitives.Graphic, I want to throw a nuke at San Fran. Â It&#8217;s a waste a time, confusing, and causes compilation problems. Â It also leads to subtle, yet horrible problems where <a href="http://www.gskinner.com/blog/archives/2010/03/building_framew.html">FlexÂ dependencies</a> get leaked into potentially awesome AS3 only libraries. Â <a href="http://github.com/mikechambers/as3corelib">as3corelib</a> is a perfect example. Â Was pimp&#8230; then someone accidentally imported mx.formatters.DateFormatter&#8230; AND YOU&#8217;RE FUCKED!</span></p>
<p>If I create an AS3 project, get your damn Flex outta my code. Â I&#8217;m Jesse Warden, you know I love Flex,Â especiallyÂ 4 now that I&#8217;ve drunken the Kool-Aid. Â But when I&#8217;m coding an AS3 only AIR project for Android to help promote your technology, and your own IDE starts getting all AS3 racist on me, it makes me RAAAGGGEEE!!!</p>
<p><strong>5. Linking Projects: Unit &amp; Visual/Functional Testing</strong></p>
<p>Linking projects is just garbage and does not work. Â One of the greatest features you all implemented in Flex 2 was Library Projects. Â Using Library projects, you can also make Design View quite useful in Flex 3. Â You just build all your GUI in the Lib, and implement with application logic in your main project. Â Since it&#8217;s a Library project that&#8217;s pre-compiled, all your graphics show up nicely in Design View.</p>
<p>&#8230;if you want to unit test or do visual tests, however, it&#8217;s a nightmare. Â In this case, I have 3 options (3rd is make your own command line build script for mxmlc).</p>
<p>I can either integrate all my unit testing code &amp; framework libraries into the project itself, or setup a new Flex/ActionScript project specifically for just testing the code. Â If you&#8217;ve ever worked with a large team, you know that the 1st doesn&#8217;t work. Â All someone has to do is get out of sync and/or break the build, and poof, productivity grinds to a halt. Â Broken builds, source control/SubClipse can get out of whack, or strange conflicts can result. Â Things happen, no big deal.</p>
<p>The big deal is you can lessen the impact by creating new projects so developers can work on their projects and do integration testing with their new code on their own terms when they are ready to lessen the impact on the team. Â It&#8217;s a very simple thing to do.</p>
<p>The problem is, this sucks. Â Linking to Library projects is magic; it&#8217;s why people still keep Flash Builder around when theyÂ primarilyÂ use FDT. Â You just click the &#8220;Add Project&#8221; button for Library paths, and BOOM, you&#8217;re linked. Â It automatically recompiles your SWC, and copies the fresh mofo over. Â No manual refreshing, no Project Clean n&#8217; Pray&#8230; it just works. Â THIS is where I&#8217;m glad some of my $5oo bucks went.</p>
<p>For projects? Â No such love. Â I have to manually point the source to the other project&#8217;s source. Â While in the same Workspace, apparently Eclipse doesn&#8217;t think that&#8217;s useful and makes me manually navigate there via Finder/Explorer. Â Worse, you have to do it AGAIN for your libs folder since it&#8217;s a source path link and not a real project reference.</p>
<p>&#8230;and it gets worse. Â Because it&#8217;s a source path to an open project, Eclipse gets confused sometimes. Â  You&#8217;ll run into situations where you can have to &#8220;MyCustomButton.as&#8221; files open. Â Which tab is which? Â Why is one &#8220;out of sync&#8221;? Â How come sometimes I compile and run and the code hasn&#8217;t changed?</p>
<p>This is even more important for components you&#8217;re testing in AIR projects. Â Most AIR projects have complicated bootstrapping, so it&#8217;s not very straightforward to just test a new AIR application (which creates yet another AIR config xml file). Â It&#8217;s easier just to create a quick ActionScript/Flex project, and test the components in isolation. Â Quicker to solve bugs too.</p>
<p>Please fix linking projects (Library projects work just fine).</p>
<p><strong>6. Design View</strong></p>
<p>What the hell did you do!? Â This worked fine in 3. Â In 4, sometimes my drops are ignored. Â My pixel perfect placements take 3 drags to get right. Â Sometimes it just gets locked up, and I have to manually hit the refresh button. Â Based on Twitter, there are only 3 other people in the world who use Design View; the rest are crayon pushers who use Catalyst, so maybe that&#8217;s why. Â Still, if you don&#8217;t want us to use it, then make it like the Behaviors Panel in Flash, and REMOVE IT.</p>
<p><strong>7. Proactive Error Checking</strong></p>
<p>mxmlc&#8217;s incremental compilation is rad. Â I know those coming from <a href="http://www.sybase.com/products/modelingdevelopment/powerbuilder">PowerBuilder</a>, Java, and other large Enterprise systems which have tools that are pretty smart at only re-compiling what is needed are somewhat critical of mxmlc&#8217;s speed. Â Whatever, if you worked on projects in Flex Builder 2, and then did projects in Flex Builder 3, it was light years better. Â If you did work in Flash IDE, then went to <a href="http://mtasc.org/">MTASC</a>, then went &#8220;back&#8221; to Flex Builder 2, then 3&#8230; it was UBER-light years better.</p>
<p>That said, the background compilation for errors doesn&#8217;t really do much. Â IntelliJ really wins here in making use of the full IDE to HELP you, vs. just inform you&#8217;re screwed, noÂ compilationÂ for you. Â Right now, most messages in Flash Builder&#8217;s mxmlc errors are good enough, and clicking on the error to go to the line is great.</p>
<p>However, IntelliJ makes the word/area red, puts red tick marks on the right side to indicate where in the class the error is, and even underlines the tab&#8217;s class name itself to imply &#8220;this class has an error&#8221;. Â That&#8217;s 3 visual indicators each covering a different spacial area all to be proactive to help you FIND problems. Â Even cooler, IntelliJ has some helpful options to import a class you forgot, show a possible mispelling, or allow you to create a class that doesn&#8217;t exist yet.</p>
<p>These common problems are old. Â IntelliJ has found ways to help you solve these common problems. Â I fail to see why at version 4 we&#8217;re still ways away from this. Â All we get a list of red dots plus reasons away from the code itself and everyone I know ignores all of them except for the 1st. Â Context is key, and in-code errors plus helpful solutions would be great.</p>
<p><strong>8. Copy Paste</strong></p>
<p>How come I can&#8217;t copy paste from Flash Builder to Flash? Â Some programs just seem to ignore the clipboard from Flash Builder. Â Others on Twitter have reported the clipboard in Eclipse is reclusive for them as well.</p>
<p><strong>9. Pasting Multiple Files</strong></p>
<p>I have flexunit4.swc, hamcrest.swc, mockolate.swc, greensock.swc. Â I copy them from my Finder. Â I paste them into my libs folder inside of Flash Builder&#8217;s project panel. Â Only flexunit4.swc makes it. God dammit.</p>
<p>Please fix this.</p>
<p><strong>Conclusions</strong></p>
<p><span style="color: #000000;">If you fix the above, you&#8217;ll start to become on par with Flash Develop/Intellij/FDT. Â Once you do that, I can justify spending $500 again for an IDE. Â Right now, beyond MXML handling, states preview, and consistent Library Project linking, I&#8217;m not sure why I paid for in my upgrade from 3 to 4. Â Whatever I can do to NOT use Flash Builder 4, I&#8217;ll do. Â Either you all were rushed, you don&#8217;t have enough money behind the project, or y&#8217;all have never used another IDE beyond Flex Builder to code ActionScript.</span></p>
<p><span style="color: #000000;">If you didn&#8217;t listen to anything I said, then for Flash Builder 5, please:<br />
</span></p>
<ol>
<li>copy Flash Develop&#8217;s code hinting</li>
<li>copy FDT&#8217;s code gen</li>
<li>copy IntelliJ&#8217;s proactive error handling &amp; auto-importing</li>
<li>copy FDT&#8217;s class re-factoring</li>
<li>fix Design View</li>
</ol>
<p><span style="color: #000000;"> </span></p>
]]></content:encoded>
					
					<wfw:commentRss>https://jessewarden.com/2010/09/adobe-please-bring-flash-builder-up-to-par.html/feed</wfw:commentRss>
			<slash:comments>129</slash:comments>
		
		
			</item>
		<item>
		<title>How Recruiters Can Hire Flex Developers</title>
		<link>https://jessewarden.com/2010/05/how-recruiters-can-hire-flex-developers.html</link>
					<comments>https://jessewarden.com/2010/05/how-recruiters-can-hire-flex-developers.html#comments</comments>
		
		<dc:creator><![CDATA[JesterXL]]></dc:creator>
		<pubDate>Tue, 25 May 2010 20:11:31 +0000</pubDate>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[hire]]></category>
		<category><![CDATA[hiring]]></category>
		<category><![CDATA[recruiters]]></category>
		<category><![CDATA[recruiting]]></category>
		<guid isPermaLink="false">http://jessewarden.com/?p=2220</guid>

					<description><![CDATA[The following article is for both recruiters, and interviewers. After doing hiring, getting hired, and helping facilitate others getting connected, there seems to be a lot of confusion in our industry about how Flex Developers work. The following article describes the different types of Flex Developers, their rates, and how to interview &#38; hire them. [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>The following article is for both recruiters, and interviewers.  After doing hiring, getting hired, and helping facilitate others getting connected, there seems to be a lot of confusion in our industry about how Flex Developers work.  The following article describes the different types of Flex Developers, their rates, and how to interview &amp; hire them.</p>
<p>Please keep in mind the following is full of (accurate)Â generalitiesÂ to make things more concise and easier to understand. Â The Flash/Flex community is very diverse, and as such there are many exceptions to the below.</p>
<p><span id="more-2220"></span><strong>Nomenclature</strong></p>
<p>W2: You&#8217;re employer takes taxes out of your paycheck.</p>
<p>1099: You are responsible for all taxes owed on your revenue.</p>
<p>W9: Like 1099 for companies working with other companies (as opposed to an individual like 1099).  Also know an as Corp to Corp/C2C.</p>
<p><strong>What is a Flex Developer?</strong></p>
<p>A Flex Developer is a programmer who utilizes the <a href="http://www.adobe.com/products/flex/">Adobe Flex SDK</a> to create either web based applications, often called <a href="http://www.adobe.com/resources/business/rich_internet_apps/">Rich Internet Applications</a>, that run in <a href="http://www.adobe.com/products/flashplayer/">Flash Player</a> or desktop applications running in the <a href="http://www.adobe.com/products/air/">Adobe AIR runtime</a>. Â They code in the <a href="http://en.wikipedia.org/wiki/ActionScript">ActionScript 3</a> programming language, and often utilize <a href="http://www.adobe.com/products/flashbuilder/">Flash Builder</a> 4 as their IDE. Â Their work usually ends up being a SWF file that runs in the Adobe Flash Player, and is accompanied by a little HTML and JavaScript.</p>
<p>A lot of Flex developers come from traditional programming/computer science backgrounds, as opposed to art/design agency backgrounds like Flash Developers do. Â Combined with the fact that the Flex community is diverse as well as continuing to utilize other technologies, many will utilize other IDE&#8217;s or a combination there of. Â These include <a href="http://www.flashdevelop.org/">Flash Develop</a>, <a href="http://www.fdt.powerflasher.com/">FDT</a>, <a href="http://www.gnu.org/software/emacs/">Emacs</a>, and <a href="http://www.jetbrains.com/idea/">IntelliJ</a> amongst others.</p>
<p>They also utilize <a href="http://en.wikipedia.org/wiki/MXML">MXML</a> and <a href="http://en.wikipedia.org/wiki/Cascading_Style_Sheets">CSS</a> in their work, and sometimes utilize other design tools such as Adobe&#8217;s <a href="http://adobe.com/products/photoshop/">Photoshop</a> and/or <a href="http://adobe.com/products/illustrator/">Illustrator</a> to integrate designs into their work. Â A select few make use of <a href="http://www.adobe.com/products/flashcatalyst/">Flash Catalyst</a> to integrate complex designs into their Flex work.</p>
<p><strong>Flash is not Flex</strong></p>
<p>While Flash Developers also code in ActionScript 3, and deploy SWF&#8217;s to the Flash Player, they are not Flex Developers. Â Flash Developers will utilize the <a href="http://adobe.com/products/flash/">Adobe Flash IDE</a>, traditionally a design &amp; animation tool turned hybrid programmer tool. Â While many are capable of creating many of the same applications that Flex Developers can create, theÂ clientele, not the developers are the defining factor here.</p>
<p>Flash Developers tend to work on smaller projects with shorter time frames, and often have a lot more design. Â The projects&#8217; development span from 1 day to 6 weeks. Â Most do not have experience creating EnterpriseÂ applications. Â Enterprise applications refer to the length of development, often from 4 months to 18 months or more. Â This deadline differentiator belies a significant amount ofÂ skill setsÂ that Flex Developers tend to have more often than Flash Developers (not always which adds to the confusion). Â Famous keywords include <a href="http://en.wikipedia.org/wiki/Object-oriented_programming">OOP</a>,Â <a href="http://martinfowler.com/articles/continuousIntegration.html">ContinuosÂ Integration</a>, <a href="http://en.wikipedia.org/wiki/Test-driven_development">TDD/Test Driven Development</a>,<a href="http://en.wikipedia.org/wiki/Design_pattern_(computer_science)"> Design Patterns</a>, Frameworks, et al.</p>
<p>To add more to the confusion, many Flash Developers employ many of the same technologies &amp; methodologies Flex Developers utilize. Â These include using alternative IDE&#8217;s, using the mxmlc compiler included in the Flex SDK, and utilizing frameworks such as <a href="http://opensource.adobe.com/wiki/display/cairngorm/Cairngorm">Cairngorm</a>/<a href="http://puremvc.org/">PureMVC</a>/<a href="http://swizframework.org/">Swiz</a>/<a href="http://www.robotlegs.org/">Robotlegs</a>.</p>
<p>If a client asks you for a Flex Developer and you send them a Flash Developer, you are making a huge mistake.</p>
<p>It all comes down to the typical clientelle the develeper gets. Â If their past projects last 4 months or longer, they can probably cut it.</p>
<p><strong>Different Types of Flex Developers</strong></p>
<p>There are basically 4 types of Flex Developers.</p>
<ol>
<li>Junior</li>
<li>Mid-Level</li>
<li>Senior</li>
<li>Architect</li>
</ol>
<p>A Junior is often someone with little experience, whether that&#8217;s in Flex, or in just programming in general. Â Fresh out of school, or just starting a new career. Â They&#8217;ve never doneÂ professionalÂ Flex Development, or little of consequence.</p>
<p>A Mid-Level Dev is often someone with some good experience, but either requires direction, or does not currently lead a team in development. Â Leading a team here doesn&#8217;t mean management; it means providing technical &#038; architectural direction to the rest of the team to ensure the project moves along smoothly. Â Often times, you&#8217;ll have senior/architect developers from other languages who are learning Flex for the first time. Â While they bring their often vast experiences, Flex is a new runtime and programming model, and as such, they are considered mid-level, and should not be leading a team. Â Either way, they only have a couple projects under their belt, or a lot of projects not in Flex.</p>
<p>A Senior Dev is someone with a lot of experience and is familiar with current, best practices. Â They have a long list of projects under their belt and a lot of experience. Â They can be depended upon to develop Flex software successfully if setup to succeed.</p>
<p>An Architect is someone who could design the entire application, from scratch, correctly. Â Often, these individuals will do back-end technologies as well to ensure they have the whole picture of how everything works together. Â They can either lead the development team, or share leadership duties with other senior level devs. Â There is crossover between Architects and Senior devs.</p>
<p><strong>How Flex Developers Work</strong></p>
<p>Flex Developers work just like any other normal person. Â Some are W2, some are 1099, and some are W9. Â You can also find all 4 skillets doing all 3 payment types. Â Most Junior and Mid-Level are W2. Â Most Senior and Architect&#8217;s are either employed at large companies that can afford their rates, or are through one of the larger consulting firms.</p>
<p>That said, finding a good W2 Flex Developer is extremely hard. Â Most Senior and Architect level developers are 1099. Â That, or they are working with consulting firms who often keep them busy. Â Thus, getting them to lower their rates so your firm can take a higher cut to work on a potentially not so savory project is hard. Â While the larger consulting firms do not always provide the top projects, because of the brands they develop, it&#8217;s easier for them to find the work that would interest Senior/Architect Flex Developers. Â This is yet another challenge for recruiters. Â The best thing you can do is be as concise and truthful (NDA&#8217;s nonwithstanding) as you can. Â If you find a Senior developer between projects, they need to eat just like Junior&#8217;s do, thus this is a great time to strike.</p>
<p>Remember, even if they aren&#8217;t a fit, they may know someone who is. Â The Flex industry is small, and it&#8217;s all about timing.</p>
<p><strong>Where Flex Developers Work</strong></p>
<p>With W2, it&#8217;s implied you&#8217;ll work on-site. Â As long as the company has benefits, W2&#8217;s are sometimes willing to relocate.</p>
<p>This is complete opposite with 1099/W9 developers,Â especiallyÂ Senior/Architects.</p>
<p>Most Senior and Architect 1099/W9 developers prefer telecommuting. Â Many aren&#8217;t willing to relocate, although many are willing to do some travel. Â Sending an email asking for W2/relocation is a sure fire way to get your email/LinkedIn/Tweet ignored by such individuals. Â If you can find out that those individuals are in fact senior, (via Blogs/Twitter/LinkedIn) a phone call is often better because you can more quickly respond that &#8220;1099 can be worked out&#8221;.</p>
<p>The telecommuting part is tricky. Â Almost all clients,Â especiallyÂ those large enough to afford Senior/Architect Flex devs, will not blindly accept telecommuting. Â Often, the engagement is of a consulting nature, and many non-progressive companies view remote with insecurity, and thus not solving their immediate cluster fire.</p>
<p>Rather than state that the position does not support telecommuting (unless you know for a FACT it does not), explain to the potential hiree that it&#8217;s up them to negotiate telecommuting terms. Â There aren&#8217;t manyÂ EnterpriseÂ sized Flex projects that are 100% remote. Â It&#8217;s MORE than reasonable for a client to expect a Senior/Architect to be on-site for the first 2 weeks, during milestones, and then towards the end of the engagement. Â That&#8217;s 15 days over the course of 4 months: completely MORE than reasonable. Â A freelancer/consultant almost can always work out those agreements with the client.</p>
<p>That said, it is a major risk, and I&#8217;ve seen people walk away from gigs 2 weeks in because these terms couldn&#8217;t be worked out which then puts your firm in an uncomfortable position. Â I recognize that educating the client on such things is challenging. Â Usually talking to the person running the project directly ensures you can get anÂ unofficialÂ yes to assuage yourÂ potentialÂ Flex candidate.</p>
<p><strong>Rates</strong></p>
<p>Rates are all over the map. Â That said, the cream of the crop has extremely high expectations,Â especiallyÂ those who live in coastal cities like New York and Los Angeles, or who are just in the know of what the going rate for their skills are. Â Here are some <a href="http://www.hotgigs.com/rates/skill/Adobe-Flex-hourly-consultant-bill-rates/">good metrics</a> I&#8217;ve seen.</p>
<p>Those who work with consulting firms, or have experience as such, will sometimes expect higher rates. Â As such, they build up a commonÂ perceptionÂ that they&#8217;ll never get work from recruiters, so just keep this mind.</p>
<p><strong>Prima Donnas?</strong></p>
<p>By this point, you may have developed the opinion that high-end Flex Developers are Prima Donnas. Â That isn&#8217;t true.</p>
<p>This is what is true: First, they know they are rare. Â It&#8217;s way easier to be a rockstar in the Flex world than the Java world. Â As such, some recognize the rules of supply and demand, andÂ capitalizeÂ on it.</p>
<p>Second, the Flex community is small in comparison to the Java, .NET, and JavaScript ones. Â This close knit nature allows the free exchange of gigs, recruiters, and general news. Â Since Flex developers have an easier access to others in the Flex community through Twitter and Facebook, and it&#8217;s easier for them to find gigs, W2/1099, on their own without the need of a 3rd party. Â This expectation, real or not, affects their communication with those offering sub-optimal rates with sub-optimal conditions (W2, on-site, etc).</p>
<p>Third, Flex is hot and new. Â This means that clients adopting it tend to have an ounce of progressiveness somewhere. Â Therefore, if you pitch the position as anything beyond hot and new, Flex devs will listen to the alarm bells going off, warning them that their attention spans may not surivive, and thus look for moreÂ lucrativeÂ offers.</p>
<p><strong>What&#8217;s a Recruiter to Do?</strong></p>
<p>As a recruiter, there are a few things you can do.</p>
<p>First, recognize the community is small, and pitch this to your client. Â Unlike Java where you have to weed through hundreds of unqualified individuals, Flex has a way smaller pool. Â Yes, it&#8217;s growing, but it&#8217;s still small in comparison.</p>
<p>Second, recognize that you only need to establish a good relationship with 1 known Flex Developer to gain access to the rest. Â No, I&#8217;m not talking about those using Monster/Dice, I mean the Senior/Architects you&#8217;d kill to give to your clients. Â Often these people participate in some fashion with the social networking scene.</p>
<p>Third, and yes, I recognize this is hard: you need to sell the project. Â Using a bunch ofÂ adjectivesÂ in a long email has the opposite effect of what you&#8217;re looking for. Â Instead, see if you can get some more real details that HR people from large companies will never give you. Â I don&#8217;t care how you do it, just do it. Â An example could include calling up the company HR:</p>
<p>&#8220;Yes, hi, this is Jamie from Tech Recruiting. Â I was hoping to get some more technical details that weren&#8217;t included on your candidate sheet. Â Could you perhaps let me ask the Director of Engineering 2 questions I had aÂ varietyÂ of potential candidates ask me?&#8221;</p>
<p>This gets you to the person who&#8217;s hiring, and hopefully can get him/her toÂ delugeÂ you with the technology stack they using. Â THESE are the keywords you want to put in your emails.</p>
<p>&#8220;Large company doing cool, new things with Flex&#8221; == pathetic.</p>
<p>&#8220;Real-time data using Blaze DS with extremely custom UI created in Catalyst&#8221; == fuck yes!</p>
<p>They wouldn&#8217;t call it work if it were easy.</p>
<p><strong>Conclusions</strong></p>
<p>Hopefully the above gives you an idea of what a Flex Developer is, how they are different from Flash Developers, and how you can lure them in. Â Flex Developers tend to build Enterprise Applications where as Flash Developers do not. Â Ensure that the candidate has past clients/work that lasted longer than 3 months.</p>
<p>A lot of the senior Flex Developers that are known in the industry are 1099 only, and many only want to do 90% telecommuting. Â These things are all about timing and who you know. Â You can&#8217;t help the first excluding being early. Â For the latter, try to get as close to a &#8220;negotiable&#8221; as you can to lure potential hiree&#8217;s in.</p>
<p>While rates are often out of your control, it&#8217;s important to set your client&#8217;s expectations. Â FlexÂ DevelopmentÂ is still new and lucrative, and the rates some people charge are outrageous. Â The recession helped a little&#8230; but not much.</p>
<p>A lot of Flex Developers know the above. Â Remember, you just have to develop a good relationship with 1 to have a gateway to the rest. Â Use small emails with enough details of what you&#8217;re offering. Â Copy pasted, 1 page or longer emails from the HR of the job with your company&#8217;s template is exactly what you shouldn&#8217;t do. Â For the record, you shouldn&#8217;t have to capitulate to a bad attitude. Â Everyone who was good that I worked with had a good attitude.</p>
<p>Anything you can do to get more technical details about what the team is actually doing makes it way easier to sell the gig. Â It also makes you extremely attractive for a Flex Developer to talk to you since you seem to know what you are talking about, and thus seem to feel that the potential hiree is right for the job vs. a blind &#8220;I found on you Google/LinkedIn/Your 6 year old Monster/Dice post with keywords in it and it&#8217;ll take 4 emails over 4 hours to figure out wtf the gig is&#8221;.</p>
<p>Finally, if you&#8217;re bold, get them to answer my <a href="http://jesterxl.tumblr.com/post/80056718/flex-interview-questions">8 Flex Developer Interview Questions</a> (skip #8 unless you know what you&#8217;re doing).</p>
<p>Good luck!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://jessewarden.com/2010/05/how-recruiters-can-hire-flex-developers.html/feed</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
			</item>
		<item>
		<title>Cocoa Chronicles #1: ActionScript vs. Objective C</title>
		<link>https://jessewarden.com/2010/04/cocoa-chronicles-1-actionscript-vs-objective-c.html</link>
					<comments>https://jessewarden.com/2010/04/cocoa-chronicles-1-actionscript-vs-objective-c.html#comments</comments>
		
		<dc:creator><![CDATA[JesterXL]]></dc:creator>
		<pubDate>Mon, 26 Apr 2010 16:59:08 +0000</pubDate>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[objective c]]></category>
		<guid isPermaLink="false">http://jessewarden.com/?p=2146</guid>

					<description><![CDATA[Skip Intro *** Update: Paul Taylor (@guyinthechair) has a more recent post on the same subject. *** *** NOTE: I&#8217;m a n00b at Cocoa and Objective C. Unlike Python, I don&#8217;t like learning it, either. If you perceive something below is inaccurate, please comment, and I&#8217;ll update. *** Preface I was having a lot of [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a href="http://jessewarden.com/2010/04/cocoa-chronicles-1-actionscript-vs-objective-c.html#intro">Skip Intro</a></p>
<p>*** <strong>Update</strong>: Paul Taylor (<a href="http://twitter.com/guyinthechair">@guyinthechair</a>) has a <a href="http://guyinthechair.com/2011/02/flash-to-objective-c-syntax-part-1/">more recent post</a> on the same subject. ***</p>
<p>*** NOTE: I&#8217;m a n00b at Cocoa and Objective C.  Unlike Python, I don&#8217;t like learning it, either.  If you perceive something below is inaccurate, please comment, and I&#8217;ll update. ***</p>
<p><strong>Preface</strong></p>
<p>I was having a lot of fun using the <a href="http://labs.adobe.com/technologies/flashcs5/appsfor_iphone/">iPhone packager</a>.Â Then <a href="http://daringfireball.net/2010/04/iphone_agreement_bans_flash_compiler">Apple changed their licensing</a> to prevent people like me from using ActionScript for iPhone/iPad, and instead being forced to use their toolsets, or those unofficially approved.  At first I was furious.  Then I tried to get a simple list to scroll in AS3.  Even using a fake mask, device fonts, and cacheAsBitmap for all items + container, it just wasn&#8217;t smooth, even with just 30 items, regardless of frame rate.  If you use an out of the box UITableView in Cocoa, it &#8220;just works&#8221;.</p>
<p><span id="more-2146"></span>I built my career on Flash Player because &#8220;it just works&#8221;.  It doesn&#8217;t &#8220;just work&#8221; on the iPhone, and now it&#8217;s effectively illegal to use.  That, and Adobe has apparently <a href="http://www.mikechambers.com/blog/2010/04/20/on-adobe-flash-cs5-and-iphone-applications/">abandoned ship</a> on the iPhone/iPad/iTouch portion, and instead are focusing on Android.</p>
<p>I was amazed at what I could do using Flash Lite 2 on my Nokia 6680 3 years ago.  AS3 was all the rage, and yet I took the time to build a <a href="http://code.google.com/p/shurikencomponents/">component framework</a> in AS2 for use on devices because I felt it was &#8220;good enough&#8221; to build experiences for consumers.  That market never materialized unless you targeted Japan (which I didn&#8217;t).</p>
<p>After finally getting my simple SWF to compile to the iPhone, I was estatic at how easy it was to design &amp; code in what I knew, it just worked, and looked like I expected it to.  Once I started moving things via <a href="http://www.greensock.com/tweenlite/">TweenLite</a>, though, it all went downhill.  I don&#8217;t have these problems in Flex.  If I use a List control in Flex, it just works; I don&#8217;t have to be an AS3 game developer to theorize on GPU acceleration possibilities to get the best list scrolling performance.  I don&#8217;t have these problems, at least from what I&#8217;m initially seeing in my early learnings, with Cocoa.</p>
<p>So, I&#8217;m learning Objective C so I can execute the ideas I have for iPhone and iPad.  Unlike PHP, Ruby on Rails, and Python &amp; Django, this has been a pretty miserable experience.  Python and Django are my choices for back-ends currently&#8230; but I don&#8217;t really have a &#8220;choice&#8221; for front ends on iPhone/iPad.</p>
<p>In an effort to reduce the pain for others as well as help myself retain this knowledge, I&#8217;m writing it down.</p>
<p>I understand it might seem strange since Android is a lot easier to develop for, and Flash Player 10.1 actually runs natively on the phone&#8230; and well, I might add.  For me, there are 3 reasons.  First, there is no market right now.  Yes, I understand we help create it, but I own an iPhone and iPad.  I love them, and so do others.  I have a gateway to others right now via the app store, and want to empower them to use my apps.  Secondly, if you&#8217;ve ever used an iPad, the additional screen real estate just fills you with ideas.  Third, everyone wants an app right now.  While the consumer data shows it&#8217;s hard to make money, it&#8217;s REALLY easy to make money for services; aka, a company hires you to build an app for them.  This is especially true with the OS4 announcement of Enterprises having more control over deploying their own applications.</p>
<p>Another good primer for me, Objective C for the ActionScript Developer, is Keith Peter&#8217;s five tutorials.  He doesn&#8217;t really cover the UIKit, just Objective C in general which is a great first start.</p>
<ol>
<li><a href="http://www.bit-101.com/blog/?p=1784">AS3 to iPhone Tutorial 1</a></li>
<li><a href="http://www.bit-101.com/blog/?p=1793">AS3 to iPhone Tutorial 2</a></li>
<li><a href="http://www.bit-101.com/blog/?p=1798">AS3 to iPhone Tutorial 3</a></li>
<li><a href="http://www.bit-101.com/blog/?p=1812">AS3 to iPhone Tutorial 4</a></li>
<li><a href="http://www.bit-101.com/blog/?p=1824">AS3 to iPhone Tutorial 5</a></li>
</ol>
<p><a name="intro"></a><strong>Introduction: Nomenclature</strong></p>
<p>There are a lot of new terms to learn.  I just want my code to run on the iPhone, yet I have to learn a bunch of new terminology to ensure I understand what it entails, as well as their &#8220;meaning&#8221;.  For example, MVC means something different to Objective C guys than it does to us.  Yes, it&#8217;s subtle, but when they say it, it&#8217;s assumed you mean &#8220;their&#8221; version.  It helps to know what the nomenclature of the Cocoa community is to learn, so first up, here&#8217;s some common terms.</p>
<p><strong><a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaFundamentals/WhatIsCocoa/WhatIsCocoa.html#//apple_ref/doc/uid/TP40002974-CH3-SW16">Cocoa</a></strong>: The API you code in for the Mac.  It&#8217;s like saying &#8220;Flex&#8221;; it&#8217;s all the things that fall under &#8220;Flex&#8221; like the compiler, the sdk, the ide, the runtime, etc.  However, it&#8217;s a lot more than that.  For example, there are Human Interface Guidelines that Apple puts out that Cocoa apps need to comply with (I don&#8217;t currently know how this is enforced, excluding iPhone/iPad).  For the sake of this article, all you care about is &#8220;Foundation&#8221; and &#8220;UIKit&#8221;, 2 libraries that make up a lot of what people know of as Cocoa for iPhone.  It&#8217;s also built on the MVC concepts we&#8217;re used to.  The main difference is Cocoa is huge; it is a layer atop an OS, whereas Flex is a layer atop the Flash Player.</p>
<p><strong><a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html#//apple_ref/doc/uid/TP30001163">Objective C</a></strong>: C like programming language you code in that borrows some cool things from Smalltalk, similar to how we code in ActionScript.  It&#8217;s from the 1980&#8217;s, and boy does it feel like it.  Anytime I start coding, I have Megadeth on in the background, my Pontiac Firebird Trans Am in the driveway does a turbo boost, and Fletch watches over me, commenting how it&#8217;s all ball bearings these days.</p>
<p><strong><a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaFundamentals/WhatIsCocoa/WhatIsCocoa.html#//apple_ref/doc/uid/TP40002974-CH3-SW20">Foundation</a></strong>: Provides all the low level stuff you need and shouldn&#8217;t have to write yourself.  This includes data types like NSNumber (vs using int/float yourself), sockets, etc.  Basically, if you can&#8217;t see it in a GUI, the class is here.  Everything is prefixed with &#8220;NS&#8221; for NextStep, one of the companies responsible for the early development.</p>
<p><strong><a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaFundamentals/WhatIsCocoa/WhatIsCocoa.html#//apple_ref/doc/uid/TP40002974-CH3-SW22">UIKit</a></strong>: All your GUI controls including support classes.  Things like UIButton, UIAcceleration, etc.  The UI prefix stands for User Interface (duh).  You&#8217;ll hear about references to Application Kit; that&#8217;s the desktop version.</p>
<p><strong>Core Data</strong>: Basically the model layer of your apps.  This is actually kind of cool, and what we should have in Flex (I know of 2 people who have tried to create an open source one, and then shortly thereafter abandoned the project&#8230; too bad too).  Right now, there are things like it in LiveCycle, I believe, but only Enterprises can afford that, so its&#8217; not for &#8220;everyday use&#8221;.  Basically, you create ValueObject&#8217;s, and they can be persisted in local XML or SQL databases automatically, vs. you having to manually write Factories, parsers, and versioning.  Pimp.</p>
<p><strong>Xcode</strong>: The IDE that you code Objective C in.  You can build &amp; debug your iPhone/iPad applications directly from here.</p>
<p><strong>Interface Builder</strong>: The IDE that you use to visually build your GUI apps.  You can actually create variable &amp; method definitions here, wire them up visually, and then have it code gen the classes for you.  It can also read your header files (imagine if every ActionScript class had an interface class associated with it that defined what it did).  As a n00b, I&#8217;ve found it really easy to confuse this program and make it explode.  Also, someone forgot to add tab order when they made it.</p>
<p><strong>Objective C</strong></p>
<p>Objective C is the programming language you write your applications in.  It is effectively an extension to ANSI C with Object Oriented syntax.  In Flash and Flex, you utilize ActionScript 3.  Objective C has a lot in common with C and C++, and some of the lamesauce as well, namely pointers.  Objective C also has multiple environs it can run on while ActionScript runs in just the Flash Player.</p>
<p>If you know ActionScript 3, you can read C, and thus Objective C.  Like Java, the type definitions are on the left instead of right, but other than that, they are extremely similar.  Like another article mentioned, if C didn&#8217;t have pointers, PHP and C would be nearly the exact same.  Since Objective C has a lot in common with C, they too are similar.</p>
<p>If you&#8217;re coding Objective C for the iPhone/iPad, you don&#8217;t get Garbage Collection, and have to manually get rid of your variables/objects.  Once you get used to the syntax, it&#8217;s almost the exact same as cleaning up your mess in ActionScript.  In ActionScript, you set your Object references to null; in Objective C it&#8217;s called nil.  More on that insanity later.</p>
<p>You can read more here about <a href="http://developer.apple.com/mac/library/documentation/cocoa/conceptual/ObjectiveC/Introduction/introObjectiveC.html">here</a>.</p>
<p>Yes, you code in Objective C 2, not 1.  1 is even more lame than 2 (thankfully?).</p>
<p><strong>Objective C Syntax: Methods</strong></p>
<p>Objective C has a lot of the same things that ActionScript 3 has.  They both use the same bracket syntax, and have the same cuddled vs. not wars.  They both end lines with semi-colons.  There isn&#8217;t as much dot syntax.  They both have methods.  Here&#8217;s how you invoke one in ActionScript:</p>
<pre lang="actionscript3">mySound.setVolume();</pre>
<p>Here&#8217;s how you invoke it in Objective C:</p>
<pre lang="objc">[mySound setVolume];</pre>
<p>Notice in Objective C, they use brackets to indicate the containment of a method call.  You can nest these as well, but they recommend you only go 2 deep since it becomes un-readable after that.</p>
<p>Here&#8217;s ActionScript storing a return value:</p>
<pre lang="actionscript3">volume = mySound.getVolume();</pre>
<p>Here&#8217;s Objective C doing the same:</p>
<pre lang="objc">volume = [mySound getVolume];</pre>
<p>Passing in parameters is a little different and takes some getting used to.  This, to me, is the same thing that threw me off in Ruby, and where Objective C totally ignores how C does it.  Here&#8217;s ActionScript:</p>
<pre lang="actionscript3">mySound.setVolume(value);</pre>
<p>And here&#8217;s Objective C:</p>
<pre lang="objc">[mySound setVolume:value];</pre>
<p>Ok, not so bad&#8230; except, the 1st parameter is always the only one WITHOUT a named parameter.  Observe the following ActionScript 3 function with 2 parameters:</p>
<pre lang="actionscript3">mySound.setLeftAndRightPan(left, right);</pre>
<p>&#8230;and Objective C:</p>
<pre lang="objc">[mySound setLeftAndRightPan:left, rightValue:right]</pre>
<p>Notice there is no &#8220;leftValue:left&#8221; here, just left.  The first parameter is always nameless, yet every one after it has one.  I guess they wanted more obvious parameters during function invocations&#8230; except forgot to build in one for the 1st parameter.  *face palm*</p>
<p>For example, here&#8217;s an ActionScript 3 function definition:</p>
<pre lang="actionscript3">private function setLeftAndRightPan(left:Number=0, right:Number=0):void</pre>
<p>Here&#8217;s the equivalent Objective C:</p>
<pre lang="objc">- (void)setLeftAndRightPan:(NSNumber*)left, right:(NSNumber*)rightValue</pre>
<p>Notice 4 important things.  First, the return type is in the beginning and wrapped in paranethesis (void in this case).  Second, notice that Objective C doesn&#8217;t allow for default values for function parameters like ActionScript.  Third, notice the type definitions for the function parameters are in the left side vs. the right (in this case NSNumber).  We&#8217;ll get to the asterisk later.  Fourth, notice the dash in the very beginning.  That signifies that this is an instance method on the class.  If you want ActionScript&#8217;s static, use + instead.</p>
<p><strong>Objective C Syntax: Variables</strong></p>
<p>Variables are slightly different because Objective C has pointers as well of built-in helper methods to make memory management easier.</p>
<p>Here&#8217;s a variable in ActionScript, first defined using a String literal (pimp syntax) and the old school way:</p>
<pre lang="actionscript3">private var name:String = "";
private var name:String = new String();</pre>
<p>And here&#8217;s one in Objective C:</p>
<pre lang="objc">NSString* name = [NSString string];</pre>
<p>There are a ton of caveats here.  Notice we&#8217;re calling the string method on NSString; it&#8217;s basically a factory method to give us a string; similar to going new String().  When I did &#8220;&#8221; above, it&#8217;s called a String literal; the same as going {} vs. new Object(), or [] vs. new Array().  In ActionScript, each of those constructors has nice features, the effect is the same; you get a variable of that type back.</p>
<p>Notice the asterisk in the Objective C example.  This means it&#8217;s a pointer to the String, not the actual String.  Also notice since we&#8217;re calling the string method on the NSString class, it&#8217;s autoreleasing (similar to the Doom spell in Final Fantasy; it&#8217;ll die soon; ie he&#8217;ll get ejected from the Pool soon, more on that later).  If you want the guy be like Number 1 and live forever instead of a Rico&#8217;s Roughneck, go:</p>
<pre lang="objc">NSString* name = [[NSString alloc] init]</pre>
<p>Just keep in mind you have to manually call release on him later whereas the former, you don&#8217;t.</p>
<p><strong>Objective C Syntax: Pointers &amp; Memory Management</strong></p>
<p>Variables are different because of a couple reasons.  First, since Objective C is based on C, it has all the pointer baggage.  We ActionScript Developers are spoiled because we don&#8217;t have do deal with this&#8230; or if we do, it requires little thought.</p>
<p>For example, in ActionScript, there are only 3 variable types that are by value, and thus don&#8217;t have pointers: Strings, Numbers, and Booleans.  Yes, I&#8217;m including int and uint as Numbers here.  Every other construct is an Object, and thus is passed by val.  If you wish for an Object based variable to be removed from memory eventually, you need to ensure no more references exist, or in the case of circular references, that no one else knows about the circular relationship (the Mark and Sweeper from the Garbage Collector will get those mofos).  For Numbers, Strings, and Booleans who aren&#8217;t local variables, you just remove their parent Object, and they&#8217;re toast.  For local variables, they go away at the end of the function (usually&#8230; depends on how aggressive the Garbage Collector is at that moment in time).</p>
<p>For Objects, you just remove all references, usually by setting them to null, or in the case of dynamic Objects like Dictionary or Object hash maps, using the delete keyword.</p>
<p>Objective C&#8217;s iPhone runtime, and ActionScript&#8217;s Flash Player both operate using reference counting.  This means, for Objects, an internal number is incremented for every person who &#8220;knows&#8221; about an Object.  When that person later set&#8217;s his reference to null, that reference count goes down.  When that reference count reaches 0, it&#8217;s eligible for Garbage Collection.  The Flash Player also has a Mark and Sweep part to take care of circular references in the case where 2 Objects know about each other, yet no one knows in your app knows about them, and thus their reference count will never reach zero.  If you&#8217;re running on the iPhone, you don&#8217;t have Garbage Collection, so need to call release yourself (which calls dealloc internally).  In ActionScript, you&#8217;d either null the reference out, or call your own destroy method, THEN null reference out.</p>
<p>Objective C has this built in as a method called dealloc.  You don&#8217;t call, it gets called for you when you (or someone else) calls release.  In ActionScript, people will either use a convention of public function destroy, or those fu@#(* IDestroy marker interfaces that people NEVER implement fully (did I mention that&#8217;s annoying?).</p>
<p>In ActionScript, for a complex class, it may look something like this:</p>
<pre lang="actionscript3">public function destroy():void
{
	if(timer)
	{
		timer.removeEventListener(TimerEvent.TIMER, onTick);
		timer.stop();
		timer = null;
	}

	if(icon)
		icon.bitmapData.dispose();
}</pre>
<p>In Objective C, this is built-in to NSObject, one of the main classes you often extend.  The Objective C version of the above would look like:</p>
<pre lang="objc">-(void)dealloc
{
   [timer release]
   [icon release]
   [super dealloc]
}</pre>
<p>As learn about how getter/setters are built into Objective C, you&#8217;ll see there is a better, and more common way to do the above (article I link to at the bottom describes this), but I need to get the point across here that you&#8217;re expected to clean up your own mess since Garbage Collection doesn&#8217;t exist, and everything can&#8217;t be an autorelease variable.</p>
<p><strong>No Local Variables, Hence Autorelease &amp; T3h Pool</strong></p>
<p>In ActionScript, we have local variables.  Basically, instead of storing it in memory, it&#8217;s stored in temporary memory that the stack is using (the stack of functions currently running).  When one stack item is done (your function is done), those variables are removed.  In ActionScript&#8217;s case, this isn&#8217;t immediate, but basically ensures that no one has references to those variables anymore.  Later, Garbage Collection will come along and eat&#8217; em.</p>
<p>Objective C doesn&#8217;t have local variables.  Yes, I know, I&#8217;m face palming as well.</p>
<p>*deep breath* There IS a common way to deal with it.  Your first thought may be to create a bunch of member variables; basically what game developers do for simple Object Pooling.  That&#8217;s ghetto, though.  You may think you could just create variables on the fly&#8230; the problem with that is you have to manually release them, and for return values, they&#8217;ll die before they get returned.</p>
<p>This is where autorelease comes in.  Remember before when I talked about the 2 ways to create variables?  Let&#8217;s revisit it, and show again how you kill things.</p>
<p>This creates a variable you must manually remove:</p>
<pre lang="objc">NSString* name = [[NSString alloc] init];
[name release];</pre>
<p>&#8230; and she&#8217;s dead.  However, here&#8217;s one that&#8217;ll be added to a pool, or rather &#8220;a Pool&#8221;:</p>
<pre lang="objc">NSString* name = [NSString string];</pre>
<p>This is the same as doing:</p>
<pre lang="objc">NSString* name = [[NSString alloc] init];
[name autorelease];</pre>
<p>You can then safely return these variables from functions, knowing that the caller will get it.  It&#8217;s also considered good practice to do, specifically for encapsulation.  There isn&#8217;t really a language construct to say &#8220;Hey dude, this guy is going to send you a variable it also has a pointer to, so please make sure you call his release first&#8221;.  Crap like that is insane; it&#8217;s just easier to get either copy&#8217;s of variables so you don&#8217;t inherit their pointer baggage, or use autorelease so you don&#8217;t piss off people getting variables from you, and causing leaks if they forget to kill you first.</p>
<p>Yes, all of that above is a shortened version of what you have to do because there are no local variables.  Yes, I&#8217;m face palming again.</p>
<p>If you&#8217;re curious about what this Pool is, imagine if a static class was created every time you ran some code.. and Garbage Collection ran immediately when you null&#8217;ed out your variables.  The first thing it did was keep a reference to any variable that has autorelease on it.  Then, 1 frame after the stack has been complete (all your code has run, and the next enter frame runs), it kills all the variables it has stored.  That&#8217;s the AS version of what an Objective C Pool is.</p>
<p><strong>Conclusions</strong></p>
<p>This sucks.  <a href="http://www.businessinsider.com/the-underlying-story-behind-adobes-failed-mobile-strategy-2010-4">I blame Adobe AND Macromedia for my suffering</a>.</p>
<p>BTW, if you&#8217;re looking for some pimp tutorials to learn this stuff, my compadre <a href="http://www.webappsolution.com/wordpress/">Brian</a> linked me to it, called &#8220;<a href="http://cocoadevcentral.com/">Cocoa Dev Central</a>&#8220;, specifically this <a href="http://cocoadevcentral.com/d/learn_objectivec/">article</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://jessewarden.com/2010/04/cocoa-chronicles-1-actionscript-vs-objective-c.html/feed</wfw:commentRss>
			<slash:comments>28</slash:comments>
		
		
			</item>
	</channel>
</rss>
