Packaging AIR Native Extensions is Horrible, but this Might Help

I’ve just spent the day learning about AIR Native Extensions. The idea is to build an Iphone app with a Flash Builder interface but using native Iphone audio capabilities. It seems that globally things have been well thought out and executed, but there’s one thing that comes across as amazingly pre-alpha craptastic: packaging your native extension. It also happens to be the worst documented, and apparently the worst understood by Adobe’s own team as their articles on the subject are misguided and confused.

The basic bricks you need for an ios only native extension are :

  • an XCode project where you code your native functionality
  • a Flash Builder Library project where you write the AS code that serves as a bridge

And then you would expect that you could point the Library project to your compiled native library, and it would produce a ANE file, ready to use. Right? Right? No.

You have to use a command line tool called ‘adt’, that comes with your AIR SDK. Fair enough. Along with a descriptor XML file. Up to there you grudgingly admit that this is new technology and that you have to put up with half-finished stuff, but where things fall to pieces is where you start dealing with the mysterious “library.swf”.

This is actually a swf that you must yourself manually extract from the swc. WTF Adobe, can’t your adt tool do this itself? So anyway: take a command line tool like 7zip and extract library.swf from your swc, and then use it in your command line. The doc mentions that the library.swf file can be different for each targeted platform. Really, I can’t what design would justify having different AS3 APIs for different platforms, but I’m new to this. Still seems harebrained though.

So after jumping through all the hoops, I ended up with the following error:

Unable to build a valid certificate chain for the signer.

Fear not, what the tutorials don’t tell you is that signing an ANE is optional! So if your signing fails, you can still use your ANE yourself, just remove the signing.

One last (bonus) hoop: The packaging settings are supposed to detect whether or not an ANE is used. At least in my test here it says it isn’t being used even if it, so don’t hesitate to tell Flash Builder to include the ANE anyway.

This article helped me the most, even if it’s for Android, not Ios.

http://www.adobe.com/devnet/air/articles/developing-native-extensions-air.html

So I worked with this example :

http://www.adobe.com/devnet/air/native-extensions-for-air/extensions/gyroscope.html

Below is my version of ./package.sh as mentioned in the article, in case it can help someone.

Continue reading →

amfPHP 2.0.1 is out!

Phew, that was hard! The goods here: http://www.silexlabs.org/131386/the-blog/blog-amfphp/amfphp-version-2-0-1-reloaded-is-out/

Looping Audio in Flash

You’d think looping audio in Flash would be trivial, right? think again. There’s enough info on the net to tell you what you need, but it’s a bit dispersed, so here it is condensed. Note that this is about looping audio that is on a server, not embedded in your swf. In that case it works out of the box.

The first thing you need is an uncompressed wave file (.wav) that contains a loop. Flash doesn’t support playback of wav files, so you need to convert it to a compressed format. You have two options here: mp3 or aac.

Mp3 has the advantage to be easy to use in Flash but unfortunately contains padding so looping it as is won’t go smoothly.

AAC can be use in Flash 10 and onwards with some trickery described here : http://www.adobe.com/devnet/flashplayer/articles/hd_video_flash_player.html. It has the advantage of not containing padding, so it loops almost perfectly. If that’s enough for you, then good. If not, read on.

If you need perfect, then this post has a pretty good method for it. http://blog.andre-michelle.com/2010/playback-mp3-loop-gapless/ It however does not tell you how to get one necessary information: the number of samples in your loop. If you encode using LAME with the command line (binaries here ), then it will tell you the number of frames. The number of samples per frame is constant with mp3s, it’s 1152. So total number of samples in loop = number of frames * 1152.

Finally, I found this approach to create a loopable mp3 interesting, but I didn’t use it : http://www.compuphase.com/mp3/mp3loops.htm

amfPHP v2 Reloaded is out

the post:

http://www.silexlabs.org/the-blog/amfphp-v2-reloaded-is-out/

the files:

http://sourceforge.net/projects/amfphp/files/amfphp/amfphp-2.0.zip/download

Linked Resources in Flash Builder

When projects relate to each other in Flash Builder, things get messy with paths. Sooner or later you end up with an absolute path in your build configuration, and that means your colleague won’t be able to build on checking out. Relative build paths would be nice, but in the meantime I found a fix that alleviates the pain: Linked Resources. The name doesn’t say much, but what it comes down to is this:

You define a path as a constant, and use it everywhere in your build paths. That way, when your colleague checks out the various projects, the only place that needs to be changed is that constant. To define such a constant, go to Flash Builder Preferences -> General -> Workspace -> Linked Resources. Add a constant, say WORKSPACE_ROOT = /Users/admin/Documents/workspace/, then use it in your project properties. For example to get a project to publish at /Users/admin/Documents/workspace/common, instead of putting that path in Flex Build Path -> Output Folder, you can put ${WORKSPACE_ROOT}/common. In this way, when you set up a workspace, you don’t have to dig through project preferences, but just need to set the Linked Resource.

amfPHP v2 Reloaded Release Candidate 1 is out

news at Silex Labs : http://www.silexlabs.org/the-blog/fr/2011/06/amfphp-v2-reloaded-release-candidate-1-is-out/

download at sourceforge: http://sourceforge.net/projects/amfphp/files/amfphp/amfphp-2.0RC1.zip/download

State of amfPHP

http://www.silexlabs.org/the-blog/fr/2011/04/state-of-amfphp/

Error Routing for AS3, a kind of design pattern and some code

There’s this piece of code I keep on using, I thought I could share it here. The idea is to keep the displaying of error messages separate from their generation.

The error router is a singleton that can be used to separate error generation from error display. Code generating an error can call ErrorRouter.getInstance().notifyError(errorData)
A visual object responsible for displaying error messages can implement IErrorDisplay and call ErrorRouter.getInstance().registerErrorDisplay(this)
If no error display is registered, a simple trace is used.

I’d post the code if posting code in wordpress wasn’t such a pain. You can download it though

http://arielsommeria.com/blog/content/error.zip

amfPHP at the “Tontons Flexeur”s Paris Flex User group

Yesterday I presented amfPHP to a crowd of Flex developers, and they liked it!

My slides, and a post about the evening, both in French:

http://www.silexlabs.org/the-blog/fr/2011/03/les-slides-de-la-presentation-amfphp/

http://www.silexlabs.org/the-blog/fr/2011/03/silex-labs-presente-amfphp-aux-tontons-flexeurs-review/

amfphp v2 public alpha

http://www.silexlabs.org/the-blog/fr/2011/02/amfphp-2-alpha1/