Archive for the ‘Tips’ Category

3-minute elevator pitch @ FOTB2010

Thursday, September 30th, 2010

So now the FOTB2010 is over and I got to do my 3-minute elevator pitch on using MIDI controllers to tweak values in flash movies in runtime.
The video of the speak along with the other elevator pitches will be available at the FOTB website, I think.
To download the classes and technology that I used at the pitch, go to http://www.molalabs.com

Color Bar

Thursday, July 8th, 2010

Manipulating bitmapdata to draw colored squares.

I’ve added some randomness based on the mouse position relative to the stage.

AS3 snippet script for mac

Friday, November 6th, 2009

I just finished the first version of a little applescript that enables you to get as3 snippets in any text editor on your mac.

Download snippets and copy it to /Library/Scripts.

Setup a short-cut… see here for an example on how to setup keyboard short-cuts. On page 3 an application called FastScripts is explained… I recommend using that.

I use the CTRL+CMD+SPACE as shortcut

When you hit your key combination you are asked to select a snippet. Press the number of the snippet you want. Then you are asked to give some parameters. Fill in the appropriate values and hit Enter. Your code will be pasted in to your editor at the cursor location.

Everytime scope is required the following can short version can be used:

pub = public

pri = private

pro = protected

sta pub = static public

sta pri = static private

The snippets:

addEventListener

parameters:

target:event (ex. myObj:Event.COMPLETE)

produces:

myObj.addEventListener(Event.COMPLETE, onMyObjComplete, false, 0, true);

private function onMyObjComplete(evt : Event):void
{
IEventDispatcher(evt.target).removeEventListener(Event.COMPLETE, onMyObjComplete);
}

removeEventListener

parameters:

target:event (ex. myObj:Event.COMPLETE)

produces:

myObj.removeEventListener(Event.COMPLETE, onMyObjComplete);

getter/setter

parameters:

name:type (ex. pub:username:String)

produces:

private var _username : String;

public function get username():String
{
return _username;
}

public function set username(value : String):void
{
_username = value;
}

var

parameters:

scope:name:type (ex. pub:username:String)

produces:

public var username : String;

function

parameters:

scope:name:return-type (ex. sta pub:getUser:User)

produces:

static public function getUser() : User
{

}

for var i

parameters:

counter:initial-value:operator:length:incrementer (ex. i:0:>:length:++)

produces:

for ( var i = 0; i > length; i++)
{

}

for var s

parameters:

key:target (ex. s:myObj)

produces:

for ( var s in myObj)
{

}

const

parameters:

scope:name (ex. sta pri:USER_READY)

produces:

static private const USER_READY : String = “userReady”;

Thoughts on debugging

Thursday, July 16th, 2009

Recently I’ve been doing a lot of debugging on several of the projects I’m working on alongside a few other developers. During this period I have come up with a few “thoughts” on good debugging procedures.

Micro analysis vs Macro analysis

Most bug reports you get are macro analysis… like “I don’t make the highscore eventhough I get the most points”. From that you cannot conclude wether the score is reported wrongly, not reported at all, not saved to database or simply just not shown in the highscore or something completely else.

In my opinion micro analysis is required. The process I follow is to figure out an in and an out point and put breakpoints from the in to the out point. Then run the application and step through the breakpoints looking at the relevant variables and verifying every action.

The process is no doubt slower than digging in directly at the point where the macro analysis states the problem occurs. But on the other hand it tend to be a lot faster in cases where the bug report is not correct.

Defining in and out points

The hardest part of the process is defining the in and out points. You want them to be as close to the problem as possible but also far enough away to be sure that you find the bug if it turns out it resides another places than where the bug says it is.

In 9 out of 10 cases some kind of user interaction starts the chain that ends in the bug. The place where the interaction occurs is a good place to start with the first breakpoint (in). In our example there most be a place where the game ends and the score is saved. This would be a good place to start.

The last breakpoint (out) should be set where the bug report specifies there is a problem. In our example I would set the last breakpoint where the view that shows the highscores is build.

The in point is more important than the out point. I usually just step through the code from the in point until I’ve found some irregularity that suggests the bug.

This is the process I run through whenever I debug code. I hope that someone might found it useful.

Flex and css: Unrecognized fill style type: 42

Monday, May 5th, 2008

We’ve had a strange bug for some time now that I’d like to share because we finally found it.

the scenario:

1 css stylesheet for a flex application.
8 windows computers with flex builder 2. 7 compiles the css perfectly the 8th throws a compile time error. Specifically: Unrecognized fill style type: 42
1 Linux server compiling with the command line compiler which also throws the error.

we tried:
copying the sdk from one of the non-complaining machines to both the windows and the linux server… it didn’t help a bit. When flex 3 arrived we tried compiling to flex 3 and all machines worked, but going back to flex 2 … the same problem.

The fix:
I figured there was only one way. Removing one line at a time from the css until it compiled. Unfortunately the line resulting in the error was embedding symbols from an extremely large swf file.
So next step was to remove one movieclip at a time to find the sinner. And let me tell you that took some time. The sinner turned out to be a shape tween. Once it was removed the css compiled as it was supposed to.

I expect the behaviour was not intentional since most machines compiled the css without any problems at all. If anyone out there run in to the same problem I hope this was helpful.

AMFPHP – Index out of bounds.

Monday, May 5th, 2008

I recently used a lot of time on this issue which exists when using AMFPHP.

the scenario:

I used a NetConnection to access an amfphp gateway. But everytime I ran my application I got a runtime error saying RangeError: Index out of bounds.

I tried to catch the error, but it seemed to happen between my call to NetConnection.call() and the callback to the Responder().

After a few hours I finally found out that my php populated an array with values in the following way

$array[1] = value1;

$array[2] = value2;

$array[3] = value3;

… and so on, skipping the 0 index.

this is perfectly alright with php. I suppose it acts like an associative array even though the keys are numeric.

But when it entered Flash it got translated into an Array instead of an Object resulting in the RangeError because the 0 index didn’t exist.

As soon as I added data to the missing 0 index everything ran smoothly.

First run

Monday, May 5th, 2008

So here it is. I finally did what I’ve been wanting to do for a while now. I went and made a blog about something I think I know enough about to interest other people… Adobe Flash… in all it’s appearences.

So in this space I’ll try to share whatever quirks and tips a know about programming flash, flex and AS3.