AIR on Android: TweetrApp Video walk-through

This the final video in my EVA series focusing on the widgets that I have created for the App in a week seminars.  As you’ll discover, it’s really very simple to create a Twitter client, and to integrate Twitter services into new or existing content to add a social element.

EVA’s social widget was created using the Tweetr component library from Sandro Ducceschi at Swfjunkie.com.  He has done an incredible job to build out a complete API for Actionscript 3 developers, taking care of the horrors of Open Authentication and connecting to the Twitter API.  It’s really as simple as creating a few objects and an application token, Sandro has also provided great tutorial videos.

Tweetr requires the open source AS3Crypto component library, a package of classes that help with encryption for client/server applications.  In this case Tweetr relies on AS3Crypto for the Open Authentication communication, another great example of how great the community is.

Finally, I spent a very long time trying to find a suitable List component for this application.  There are many great sets of components out there, not least of which is Flex.  Of course Flex on Mobile devices is going to take some time, so I was glad to finally come across FlepStudio.org and the Tipper component.

If you want to learn more about mobile optimization then drop by the mobile pages at the Developer Connection.  Also coming up in June are some great e-seminars where you’ll learn more about going multi-screen.

Download TwitterApp

Flash Builder Profiler – Fixing Memory Leak on ExternalInterface

One of the most common problems with Flash applications are memory leaks, programming flaws that cause Flash Player to loose access to memory that it could recycle otherwise.  In the mobile space it’s crucial to understand memory management to get the most out of the Flash Player, and ultimately to ensure a smooth ride for your consumers.

Flash Player memory management

Flash Player makes use of automatic memory management, to help you to create applications with ease and with less code. In fact the Flash Player uses a pretty simple mechanism that determines how many times you have referenced a particular object. Once an object has nothing referencing it then it can be garbage collected – predictably it’s called “reference counting”.

The following is a great example of reference counting in action, notice that I have created a Geolocation object (geo) and added updateHandler as a listener function for update events.  This counts as a reference against updateHandler:

var geo:Geolocation = new Geolocation();
geo.addEventListener(GeolocationEvent.UPDATE, updateHandler);

function updateHandler(event:GeolocationEvent):void
{
geo=null;
trace(event.longitude);
}

The updateHandler function marks the location object null, tagging it for deletion by the garbage collector which is great.  The problem is that the location object still has a reference to updateHandler, and therefore the location object cannot be deleted until that function looks like this:

function updateHandler(event:GeolocationEvent):void
{
geo.removeEventListener(GeolocationEvent.UPDATE, updateHandler);
geo=null;
trace(event.longitude);
}

Memory leaks are easy to create in Flash, and even harder to debug later.  It’s therefore essentially to build your applications with memory in mind and use all tools at your disposal to keep checking for leaks, slow performance, and run away code.

Flash Builder Profiler

Flash Builder 4 ships with a new feature called the Profiler and in the video below I’ll show you how to use it to solve a memory leak.  Now don’t be fooled, this memory leak took a few hours to solve in reality – these aren’t easy problems to solve.

In fact I found two memory leaks, the first is the ExternalInterface.addCallback holding onto a function reference.  The other is more complex, and I have marked it “Flash Player Bug” as I believe this is a problem with the runtime itself.

Getting started with Flex 4, Flash Builder 4 and ColdFusion Builder

I’m pretty sure you will have heard that the Flex 4 SDK, Flash Builder 4 and ColdFusion Builder have been released today. If not, check out Andrew Shorten’s blog post on the Flex Team blog.
Andrew Shorten: In the Flex 4 SDK, we’ve implemented a completely new component and skinning architecture (Spark) that supports a level [...]

Flash Builder 4 and Flex 4 Released

It feels like a long road, but today we’re releasing the final versions of Flash Builder 4 and the Flex 4 SDK. If you were one of the attendees at Flash Camp Boston, you got the final versions on the DVD (but we had to call it a release candidate) so there’s no need to update. For the rest of you, make sure to grab the latest and greatest right now. If you’ve installed previous betas/prerelease versions, you will need to uninstall those before you install the new versions.

I’ve been a Flex developer for a long time, since version 1.5, and I genuinely think this is the most significant release in the history of Flex. We made some huge architectural changes in this version of the SDK. The new skinning model which separates the logic of a component from the look and feel is going to let you create some very complex and unique user interfaces. An improved states model along with a much more efficient transitions/effects engine mean that it will be easier to create multi-screen applications with meaningful rich transitions. And arguably the most important thing we did was optimize. The compiler is much faster which means you’ll be spending less time compiling and more time building.

But the biggest thing about this release in my mind is Flash Builder. This tool has come such a long way and Flash Builder 4 is a home run. The added productivity enhancements like ASDoc support and event handler generation make it so much nicer to program. Throw in things like better refactoring and built in unit testing and you’ve got a very powerful IDE on your hands. I’ve been using it for a while now, but when I step back and look at it, I’m very happy with what the team accomplished. Hopefully you also enjoy the new network monitor and the DCD features which make it easy to connect to data and start building RIAs. And with the new leadership in place, the future of Flash Builder is only going to get better.

I’ve got a bunch of articles up on the Developer Center for using Flash Builder 4 with PHP. If you’re a PHP developer interested in testing the new features, these should get you pointed in the right direction. We’ve also got recordings up of all the talks at Flash Camp Boston which cover a variety of Flex 4 and Flash Builder 4 features as well as some thoughts straight from developers who are going to be using Flex 4 and Flash Builder 4.

Congrats to the teams who made this happen. I hope you all enjoy the hard work that went into the release.

Flex 4, Flash Builder 4 and ColdFusion Builder go GA!

We are very excited to announce the final releases of Flash Builder 4, Flex 4 and ColdFusion Builder. These releases bring together two years of engineering effort and some big advances in how you can now build rich Internet applications. We’ve also released a ton of great new free learning resources to help you put these new tools to work in building RIAs. You can hear from developers at our recent Boston Flash Camp where Ryan, Deepa, and team provided a deep-dive on all the features, and even talked about the little stuff that we don’t talk about much but can really make a difference in your application development. You can watch all the sessions from the Boston Flash Camp on Adobe TV.

These releases provide tremendous new capabilities including:

  • The revolutionary Spark components in Flex 4 enable far more expressive interfaces to be easily created, and pave the way for Flash Catalyst.
  • The Data-Centric-Development (DCD) capabilities of Flash Builder make it radically easier to work with data and web services.
  • Flash Builder’s new developer productivity features such as advanced debugging and improved refactoring, coupled with compiler performance improvements make Flex development faster and easier.
  • ColdFusion Builder addresses the number one request of the CF community, providing extensive IDE capabilities and making CF development much more productive.

So have at it.

Get Flash Builder. Get the Flex 4 SDK. Get ColdFusion Builder.

Mapping Data Types from PHP to Flex with Zend AMF and Flash Builder 4

I assume this has to be out there somewhere but I couldn’t find it so hopefully this helps someone who Google’s things the same way I do. And Wade has a great tutorial for doing this when you’re just dealing with the Zend AMF code but I was looking for something that worked with Flash Buidler 4’s wizards.

While using the Flash Builder 4 data-centric design wizards to generate the service calls for a PHP class I was having trouble figuring out how to make sure that the data types I had set up in my MySQL database were being carried all the way through to my Flex application. When I retrieved data from the database in PHP and then had Flash Builder 4 inspect my class, the properties of my returned class were all strings.

If you use the data-centric design wizards to create a class based on a database, the class properties are typed correctly. If you use a class you’ve already written, all of the properties come back as strings. Luckily I chatted with our Flex/PHP guru, Mihai Corlan, and he pointed me in the direction of type casting.

Essentially you just need to add a bit of extra data when the properties are returned in the class so that Zend AMF knows what type of data to expect. So for my getAllItems() method, I iterate through the records of my database and create a PHP object for each one.

As you can see in the code below, to return as an int, just add a 0, to set it as a number, add 0.0, to set it as a date, just create a new DateTime object with the data from MySQL. As you can see from the Mapping Table you’ve got coverage for pretty much every data type.

public function getAllForests()
{
$this->connect();
$rs = mysql_query("select * from national_forests")
or die ("Unable to complete query.");
 
$national_forests = array();
 
while( $row = mysql_fetch_assoc($rs) )
{
$forest = new NationalForest();
$forest->id = $row['id']+0;
$forest->state = $row['state'];
$forest->area = $row['area']+0.0;
$forest->established = new DateTime($row['established']);
$forest->closest_city = $row['closest_city'];
$forest->name = $row['name'];
 
array_push($national_forests,$forest);
}
 
return $national_forests;
}

If there’s a better way to do this, I’d love to have it.