Make On-device Debugging Easier with iFunBox

I’m working on an Adobe AIR iOS project for the first time and I feel that on-device debugging is too slow. These steps could take a few minutes (which I think is too long in today’s standard):

  1. Build the project in FlashBuilder & wait for the debug popup
  2. Use iTunes to remove the app from your device if it’s already there
  3. Add the .ipa to iTunes library
  4. Sync your device and wait until you see the app icon on your device
  5. Launch the app
  6. Go to FB’s debug view

Doing all that once in a while may be OK but many times in a day? It puts strain on my wrist. Even worse, I have to do it every time I want to test my app. I know I could use AIR iOS simulator for quick tests but unfortunately it never worked for me; for some reason, TouchEvent and MouseEvent never dispatched, even when I tried the sample code from AS3 doc. So on-device debugging/testing is the only way for me.
Continue reading →

Learning Gideros (and Lua) : Porting Advanced AS3 Animations code

Today I had a chance to play with Gideros SDK. In order to get a better understanding about the SDK and Lua in general, I decided to port some AS3 code. Here are some code from Keith Peter’s book, Advanced AS3 animations, in Lua.

I haven’t fully understood Lua so these code might look bad in the eyes of Lua experts 🙂 but at least it works.

[note color=”#FFCC00″]You can get the original, fully commented AS3 code from http://www.apress.com/9781430216087[/note]

First, the Vector2D. I don’t know if Lua has a built-in Vector class, maybe it does but as part of the learning process, I wrote one myself. Porting Vector2D.as to Vector2D.lua was almost as easy as copy-pasting.

--[[
Vector 2D class. Ported to Lua from Keith Peter's AS3 Vector2D
Author : Anggie Bratadinata | www.masputih.com
--]]

Vector2D = {}
Vector2D.__index = Vector2D

-- constructor
function Vector2D.new(initX,initY)
	local instance = {
		x = initX,
		y = initY
	}
	setmetatable(instance,Vector2D)
	return instance
end

--[[
	BASIC MATH OPS
--]]

function Vector2D:dotProduct(v2)
	return self.x * v2.x + self.y * v2.y
end

function Vector2D:angleFrom(v2)

	local v1 = self
	
	if self:isNormalized() == true 
	then
		v1 = self:clone()
		v1:normalize()
	end
	
	if v2:isNormalized() == true
	then
		v2 = v2:clone()
		v2:normalize()
	end
	
	return math.acos(v1:dotProd(v2))
	
end

function Vector2D:add(v2)
	self.x = self.x + v2.x
	self.y = self.y + v2.y
end

function Vector2D:subtract(v2)
	self.x = self.x - v2.x
	self.y = self.y - v2.y
end

function Vector2D:multiply(value)
	self.x = self.x * value
	self.y = self.y * value
end

function Vector2D:divide(value)
	self.x = self.x / value
	self.y = self.y / value
end

--[[
	LENGTH
--]]
function Vector2D:setLength(value)
	local a = self:getAngle()
	self.x = math.cos(a) * value
	self.y = math.sin(a) * value
end

function Vector2D:getLength()
	return math.sqrt(self:getSquareLength())
end

function Vector2D:getSquareLength()
	return self.x * self.x + self.y * self.y
end

-- normalization
function Vector2D:normalize()
	if self:getLength() == 0
	then
		self.x = 1
		self.y = 0
	else
		local l = self:getLength()
		self.x = self.x/l
		self.y = self.y/l
	end
	return self
end

function Vector2D:isNormalized()
	return self:getLength() == 1
end

--[[
	ANGLE
--]]
function Vector2D:getAngle()
	return math.atan2(self.y,self.x)
end

function Vector2D:setAngle(value)
	local l = self:getLength()
	self.x = math.cos(value) * l
	self.y = math.sin(value) * l
end

--[[
	DISTANCE
--]]

-- get the distance of the given vector from this vector
function Vector2D:getDistanceOf(v2)
	return math.sqrt(self:getSquareDistance(v2))
end

function Vector2D:getSquareDistance(v2)
	local dx = v2.x - self.x
	local dy = v2.y - self.y
	return dx * dx + dy * dy
end

--[[
	UTILITIES
--]]

-- determine if the given vector is to the right (+1) or to the left (-1)
-- of this vector
function Vector2D:getSignOf(v2)
	local perp = self:getPerpendicular()
	if perp:dotProduct(v2) < 0
	then
		return -1
	else
		return 1
	end
end

-- return a new vector that is perpendicular to this vector
function Vector2D:getPerpendicular()
	return Vector2D.new(-self.y,self.x)
end


function Vector2D:truncate(maxLength)
	self:setLength(math.min(maxLength,self:getLength()))
end

function Vector2D:zero()
	self.x = 0
	self.y = 0
end

function Vector2D:isZero()
	if self.x == 0 and self.y == 0
	then
		return true
	else
		return false
	end
	
end

function Vector2D:equals(v2)
	return self.x == v2.x and self.y == v2.y
end

function Vector2D:clone()
	return Vector2D.new(self.x,self.y)
end

function Vector2D:toString()
	print("Vector2D[",self.x,",",self.y,"]");
end

-- so that this class can be imported by "geom.Vector2D"
return Vector2D

Continue reading →

Easy Inheritance & Modularity in Lua

Seeing many flash developers praising Lua-based SDKs like Corona and Gideros that allow us to create mobile games quickly, I couldn’t help trying them myself.

First thing I did was read up some Lua tutorials. The language seems pretty easy to grasp — everything is a table which looks like associative array or a Dictionary in AS3. Good. Until I got to the point where I want to apply/emulate OOP or write code in modular fashion. This is where things become confusing because code examples from Corona and Gideros show you how to shove everything in one big main.lua file. To add even more confusion, different Lua OOP examples show you how to emulate OOP in different ways. And there are things called metatable and metamethods.

After an hour reading the docs and wiki and doing some experiments. I found that it’s really not that hard. Here’s an example of inheritance in one big file.

Continue reading →

How to Use SWC as RSL in Pure AS3 Projects

Using SWC as RSL in Flex projects is a no brainer. Flash Builder and Flex ant task automate a lot of things for your convenience. Unfortunately, that’s not the case with pure AS3 projects. I read somewhere that you can use a special Frame tag and a factory class to load the RSL swf before you instantiate your document class. I tried that but I got mixed results; it didn’t always work in all cases especially when the SWC contains a lot of assets. I might be doing something wrong; I don’t know.

It turned out that you can use a “loader” SWF to load the RSL swf before your main SWFs to achieve the same thing. That left me with one problem, how to get the RSL swf out of the SWC. As we know, SWC is just another compression format, just like zip so any zip expander/extractor will work but manually extracting the SWC is going to be a pain in the @$$ and you’ll have to do it every time you update your SWC. This is where Ant becomes your best friend 😉

In this post, I’ll show you how to do it with Flash Builder & Ant.

Creating Projects

First, we create a new workspace and add build folder to store the published SWFs and then create the projects below:

  1. MyLibs – Flex library project. This is the RSL to be used by AppOne and AppTwo.
  2. AppOne – AS3 project
  3. AppTwo – AS3 project
  4. loader – AS3 project that will load all other SWFs

Then we add a Car class to MyLibs project and compile the project so we have MyLibs.swc in its bin/ folder.

Continue reading →

Easy Undo & Redo in ActionScript

Some weeks ago, I needed to add undo-redo functionality to a project (a photo album editor made with Flex) and here’s what I came up with.

How to use the demo : Click “Add” button & click the grey sprite to add a square. Click “Remove” & select a square to remove it. Click “Rotate” then select a square to rotate it. And so on.

Download

Here’s the source [download id=”16″]

Enjoy.