Clang + LLVM a must have tool for iPhone Developers

If you’re new to iPhone development or coming from a web developer background you’ve probably never had to deal with memory management.  I was in that same boat.  One of the great benefits of being a Flex Developer, I’d leave all of the garbage collector and memory management to the Flash Player.  Unfortunately the iPhone platform doesn’t have that luxury. (Though objective-c does have garbage collection in OS X development, just not on the iPhone)

Have no fear, scan-build is here..

The command scan-build is part of the Clang llvm toolset.  It’s a parser that goes through your code and looks for bad things in your code, including memory leaks!  It generates a really nice graphical HTML report that shows you which file and which line of code your leak occurs.

Once you get everything installed, “cd” into your project directory and run the command below:

cd projDir/
sudo scan-build -v -analyze-headers xcodebuild

Optionally you can have xcodebuild -sdk Debug

Once it’s done running, it will probably output all of the html files under /tmp.

What I do in my project settings, is set “commandline to default to Debug”.  The main caveat is that you can’t run the xcodebuild command to a device project build.  It has to be on a simulator and debug setting for the reason of digitally signing stuff.  It will error out and stop and will give you an error message about code signing.

One last issue I ran into is when scan-build ran, it would actually lock the file permissions of your build/ directory in your project.  So usually I do a “clean all targets” before I run scan-build, and then delete the build directory after I’m done running scan-build.

Cheers,
–lp

Another 360Flex conference? That means another Charity Code Jam!

After 7 months of straight iPhone development and the release of My Style, I needed a vacation.  I found some really cheap tickets from slow-hare (ORD) to London (LON) for $165 and I was almost set to book everything when lo and behold my friend Shannon Hicks at Webapper told me that there was going to be a Charity Code Jam at the 360Flex Conference in Indianapolis!  Game on!  Who would have thought a “vacation” would be trying to stay up for 60 hours straight and code for charity?  This guy.  I wouldn’t have it any other way.

This year the Charity Code Jam supported the Leukemia & Lymphoma Society (LLS).  The scope of the app is to build an app for the Nike Women’s Marathon.  A flex based runner tracking system utilizing live GPS and RFID streaming data. The purpose is to auto check-in runners as they make it over the finish line. This would be assist in mapping out progress of a runner in live-mode, assist LLS staff in the check-in process but also help provide information to runner’s coaches, supports and LLS Staff.

The code jam was another great experience.   I got a chance to meet a lot of developers and it was a great way to get back into Flex development!   Photos of day 1 and day 2 can be found here as well as a video of Ali presenting the application.

I definately have to tip my cap to 360ConferencesWebapper and the other sponsors for making it possible.  I’ll have to put London back on my “places to visit” list.

–lp

The Return of the Thinker

It’s been a about 10 months since my last post and a lot of you have wondered where I’ve gone.

I decided to take a sabbatical from Flex consulting to pursue an idea I had for the iPhone.  This was a very difficult decision for me, but I realized I was in a very good position to take a chance, and I may never get another opportunity like this again.  I am proud to say that 2 weeks ago the iPhone app is now available on iTunes.  You can also see the app at http://mystyleapp.com

Now that I am able to take a breath of air, I’ll be back.  Not like an Arnold, “I’ll be back” or back like Jordan - I simply have time to share things with all of you again and this time with iPhone experience.  I want to thank everyone for their support!

–lp

Hello Flex Logging and Goodbye trace()

Being a long time Flash Developer, using the trace() method was the first solution to trying to debug a problem. “Just trace out the value and see what it is and go from there”. I kind of laughed when someone at the office called it “poor mans debugger”. Scary enough, the more I thought about it, the more I realized he was right. Since the Flex Builder debugger, I rarely trace() anything out to the console anymore. I still trace things out in my application, a service or an action so I know that things happened properly.

I also remember discussing in #flex (on irc efnet) that there isn’t a compiler option to strip out all trace() statements in a swf. I believe people even created tickets on the Flex bug base for this. For me I’ve always accepted that since the old Flash 4 days, but there are some plugins now that allow you to see all trace statements in a SWF. This is all the more reason to use the Flex Logging classes!

First off, the Flex Logger basically wraps to trace() but the benefits of the flex logger are more flexible than trace. Let’s start with the different levels of logging: Debug, Info, Warn, Error and Fatal. This allows you to display the level of trace out to the console. For example, mylogger.info( “startup” ) or myLogger.debug( “event name” ). The great thing about these different levels is the TraceTarget class has a “level” property that you set that will only display that level of logging and higher. For example if you set the target.level to LogEventLevel.Debug, it will show everything from debug up. But if you set it to LogEventLevel.Warn, it’ll only show warnings and errors. To me, this solves the need of having a compiler option to omit trace actions.

Another great benefit of the flex logging classes are there are already a few packages that implement them: mx.rpc.*, mx.messaging.*, mx.data.*. It was really neat to see this in action for the first time, I made a RemoteObject call to the server and it traced out all of the info related to the call, and even the value object from the server. Again, the traces can be omitted via the “level” property.

I will agree with the saying, “Old habits die hard”, but when I started using the Flex logging classes, it wasn’t a difficult transition at all. If you’re an old Flash Developer turned Flex, I strongly urge you to check out the Flex Logging classes!

Cheers,

-lp

Flash Media Server Feature Explorer

Ok, so I haven’t posted in a while. I figured this post would have to contain evidence that I haven’t just been golfing all summer (hehe).

Nathan Weber, Peter DiLillo, and myself over at Digital Primates just released the Flash Media Server Feature Explorer on Adobe’s Flash Media Server DevNet. If you haven’t checked it out yet, I really hope that you do. It’s an Adobe AIR app that showcases 30 samples on how to use Flash Media Server with Flex and AIR.

Cheers and I’ll be posting more soon! I promise!

–lp

Merapi says “Hello World”… World say “Hello Merapi”

If you haven’t already seen the screencast or Dave Meeker’s blog post of Merapi in action, you should definitely check it out! I am very excited for the next months to come.

Stay tuned for an update on my original scanner demo with AIR. Since Adobe’s Blaze DS is under the hood, Merapi will allow me to send my scanned image as a ByteArray back to Flex from the scanner! Better yet, our external Java libraries can now initiate data transfer to AIR. It’s no longer a one way street! A private alpha will be on it’s way very soon but in the mean time, imagine what kind of devices you could integrate into your AIR apps!

–lp

RIA Dev Shed 2008 - Presentation Files

As promised, here are the files for my presentation - Flex and Flash Media Server 3 from RIA Dev Shed 2008 in Utah. Special thanks again to the sponsors (Adobe, Twelve Horses, SLCFUG, NUCFUG, Vox Pop Design) for putting together the event.

RIA Dev Shed Presentation
(Photo by libel_vox)

 

I personally want to thank Matthew Reinbold for putting together the event! He was a pleasure to work with! Thanks again Matthew!

As3Regex Tester

I think one of the coolest addition to AS3 is regular expressions. If you’re like me, you’re probably way out of practice and it would take you awhile to finally get the proper expression to match or replace. So I went online and found a good client-side regex tester. What I quickly learned is that regex has different variations between languages. What I was using online, VBScript or JavaScript regex wasn’t the same standard of stuff I was trying to match using AS3. So I just tried to do the regular expression from flex, and doing a quick compile to see the results. This got really annoying really fast!

As3Regex Tester Screenshot

So enter As3Regex Tester! I decided to write a regular expression tester for ActionScript 3. It supports switching between match and replace, as well as onChange() on the <mx:TextArea> so you can see your changes immediately.  You can also select the specific flags such as global, lower case etc.  It also supports string saving.  It saves the strings to a Local SharedObject so you don’t have to keep pasting in text!

I think the funny part about this application is the UI.  I am a designer and I usually really care how my applications look but I figured the engineers that need regex don’t need a fancy UI ;)

Anyway, I hope you like it!

–lp

Using Flex Framework libraries in an ActionScript project

One of my favorite things about Flex Builder is that you can create a pure ActionScript project that extends Sprite. I can’t imagine writing a Flash application these days without doing it in Flex, but this option is great you’re looking for something more lightweight or if it’s a non-UI project such as a SWF bridge to manage old AS1/AS2 content. Other things could be a Papervision 3D project or if you’re playing around with programmic movement or the drawing API.

It’s still a surprise to me that a lot of hardcore Flashers do all of their work in pure AS3 but still haven’t heard of binding. I thought I’d show how you can use binding and other Flex libraries. There is a “gotcha” or two along the way but I plan on explaining those too.

Lets start out by looking at some of the Flex libraries with the Flex SDK. Go into your Flex Builder installation directory and you should see the following folder path:

{FlexBuilder 3 Location}\sdks\3.0.0\frameworks\libs

It should contain some SWC’s like:

flex.swc
framework.swc
rpc.swc
utilities.swc

These are available for you to use in any ActionScript project, you just have to add them. So to add them right click on your ActionScript project and select properties.

ActionScriptProperties

This lists the existing build path libraries for the compiler. We’re going to add a few more. So go ahead and click on the button “Add SWC” or “Add SWC Folder”. You can add the entire lib directory we talked about above, but it has additional SWC’s you may not need like the automation testing and QTP classes. I just add them individually. Once you add all of them we now have to add the “locale” folder. This locale folder is used by the libraries for error warnings etc and is specific to the language you specify. So click on “Add SWC Folder” and select a similar location:

Locale Location

Now your properties should look similar to:

finallibraries.png

Click ok and wait for it to update the compiler settings. So now you’re ready to use binding and all of the Flex libraries! You also now have the code completion and all of the other good stuff that links to the libraries.

We’re not completely out of the woods yet, we do have to cover one more important item about implementing the actual Flex classes. Lets use mx.rpc.HTTPRequest as an example:

var myURLRequest:URLRequest = new URLRequest( tmpString );
var myService:HTTPService = new HTTPService();

myService.method = "GET";
myService.url = myURLRequest.url;myService.addEventListener( ResultEvent.RESULT, onHTTPServiceComplete, false, 0, true );
myService.addEventListener( FaultEvent.FAULT, onHTTPServiceError, false, 0, true );

myService.send();

This is very valid but it’s actually going to throw the following runtime error in your project:

No class registered for interface ‘mx.resources::IResourceManager’.

Believe it or not, during the initialization of a Flex Application, many classes are loaded to be used later. The solution is to create a method called initFlexFrameworkSpecifics() which you call in your constructor or inside init() and have the following code:

private function initFlexFrameworkSpecifics() : void
{
    Singleton.registerClass("mx.resources::IResourceManager", Class(getDefinitionByName("mx.resources::ResourceManagerImpl")));
    var resourceManager:IResourceManager = ResourceManager.getInstance();
}

HTTPService was making call to a IResourceManager which didn’t exist.  The Singleton Class reference is what the Flex Framework does to ensure there is only one instance of your class. So what we do is create that class reference of IResourceManager for all other libraries to use.

That’s it! You’re good to go now.  Please understand that there may be more libraries that you’ll have to initialize depending on which classes you use. I hope you find this post helpful!

–lp

Eclipse “TODO/FIXME” Goodness

I’ve been meaning to try this TODO/FIXME plug-in for eclipse sometime now. If you haven’t already installed it, you definitely should try it out.   I think it’s very handy! This is going on my list of default plug-ins to install along with the viPlugin and Subclipse. Yet another great tool released by the community!

Louie Penaflor is a web developer in Madison, Wisconsin specializing in Flex, Flash and Design. The views expressed on this blog are personal views and should not be taken to represent corporate strategy or official Digital Primate positions. The content of the posts at this site should not be re-distributed by commercial media.