Archive for Flash Professional IDE

Mr. Jobs the Great and Flash

So Mr. Jobs the Great had his “Thoughts on Flash” today.

The most important question to me, why he post such a public letter dedicated on Flash?

He fears.

A large number of devices, from Google, HP (with Palm), RIM, and other big companies, attacking the market share of iPhone, iPad very soon, with Flash. It’ll be threat for his early comments on Flash. He fears his words broken.

His App Store was a great success, but his decision to kick CS5 out from iDevices, which also drive away developers who planned to write apps with Flash. Instead he hoped us developing with Apple-C (yes we can, but we choose not), lots of CS5 developers will develop apps for his competitors. He fears his store no longer moving to next billions.

As one of the greatest CEO in the world (yes exactly he is, with great respect), he fears the decision to reject Flash, Flash designer/developer community is a fault, he’s now on the top of mountain, higher risks than his days in the valley. He fears he’ll no longer Mr. Jobs the Great.

We believe in Choice

Mr. Jobs believe in choice, other than Flash, developers can write application with Apple-C, or Javascript. We too, we believe we have options to use better tools at our hands, not forced to use specific technologies. If Mr. Jobs did the right decision, there will be a number of developers use Flash to develop apps quickly, if we find some performance or other problems, we can rewrite with Apple-C not Flash for best user experiences for consumers (we can even write with assembly).

Otherwise, the choice for iDevice, return -1.

SQLite as Service in AIR (Flash/Flex)

I introduce here is my approach (not fully complete framework), to use SQLite like an external service in AIR, in most simple way.

The following code is how it to be used in Flash/Flex application:

That simple? Sure it is.

Don’t forget, in AIR applications, using SQLite we MUST use asynchronous connections for user experiences. The framework will do rest hard jobs for you.

Framework Features:

  • SQLConnection instances reused.
  • SQLStatement instances reused.
  • Statements executed in queue automatically, no extra control required.
  • Dealing with SQLite locks inside framework.
  • Feedback(result/fault) functions can be reused, similar with pureMVC’s handleNotifications.
  • Support to run feedback functions not original object, i.e. a view sent a query then closed, after query complete, run feedback function in another object/view.
  • All statement/connection objects managed and resources can be cleaned.

SQLite Performance Best Practices

It’s important to get benefit of maximum performance of database, SQLite has its own specifications. One of them, Adobe has already documented, is the cached statements, cached statements can be reused and increase performance largely.

The second one, I didn’t see anyone mentioned it (maybe I missed), is the lock system of SQLite.

SQLite has a special lock system, have a look the figure followed:

Here’s several important rules about SQLite lock system:

  • A connection can have only one transaction (working statement) at a time.
  • SQLite can have multiple read transactions(read statement) and one single write transaction(write statement) at the same time.
  • When the write transaction working or waiting, no more new connections can work.
  • The waiting write transaction will be executed only after all other read transactions complete.

The third one, using SQLTransactionLockType.IMMEDIATE for write transaction can improve performance when necessary.

My solution implement first and second, the last one I didn’t find a good solution to use it in asynchronous connection mode, will talk it later.

Framework Structure

The framework include three major classes:

  • SQLManager
  • ConnectionPool, manage and reuse connections for statements.
  • StatementManager, add/remove statements.

These object classes/interface used by the framework:

  • SQLiteStatement, after an operation finished, it run feedback based on caller and function(string). Feedback function can be different to the original view(object).
  • SQLiteConnection
  • CachedStatement, statement cannot to be run immediately will be cached as a CachedStatement in waiting list.
  • ISQLResponder, optional interface for caller view/object.

Framework workflow

  • Create instance for a database file (file can not exist even)
  • Add statements when needed, statements will be initialized.
  • View call for execute one or several statements with statement_id, set result/fault function, and flag whether need to ignore fault (if ignore, sqlite will continue to run waiting statements)
  • SQLManager get statement instance, or cache your request to a waiting list if already used.
  • SQLManager ask ConnectionPool to apply a SQLiteConnection for statement to execute.
  • Statement try to execute, if SQLConnection not connected, waiting for that connection and execute.
  • Statement completed/fault, call feedback function with statement_id (if asked), and execute next waiting statement if exist.

The framework keep minimum instances of SQLConnection and SQLStatement, and easy to be removed as they’re managed for garbage collection.

I’m not going to publish source code right now as it’s not a complete framework yet.

AS3 Obfuscation and Decompiler Test

Shocked by Doug Mccuue’s post, I decided to have a test on obfuscation and decompiler together, to see how safe my own Flex/Air code bases.

SWF Encrypt

For a long time I was impressed by SWF Encrypt, although it’s not a real encryption, should be something interest if it can obfuscate code well for me.

Sothink Decompiler

In AS2 days I used to use the free Flare written by Igor Kogan, it was a great tool to help to search where co-workers hide their code inside FLA files. But now I need a AS3 version it no longer support. I read a post by Lee Brimelow about Sothink decompler several months before, so I would like to give it a try.

Test

SWF Encrypt trial version let me try 25 times, I made a secure swf from my AIR swf file.

Sothink Decompiler can read my origin AIR swf file easily, include almost all assets and code packages. Unfortunately the trial version do not let me check source code.

I found code structure in Sothink quite clear and accurate matching my own code base. I decided to buy it as the price not a problem $79.

Result

From my original AIR swf file, Sothink can read almost all my code, that….hell!

From secure AIR swf file, Sothink again, read most of my code, only several properties and function names hide.

Conclusion

First, the dark side, our code is definitely not safe.

Second, I do not feel SWF Encrypt doing its own job, I hope it can at least change my property/function names so even decompilers can take out all code, still hard to understand. SWF Encrypt really hide several properties/function names, but only very few of them.

Third, I found Sothink useful. Flex framework itself is a giant code base, Sothink decompiler code give some other code we cannot see and realize in MXML files.

Update: finty is right. I forgot Flex compiler can generate source code itself.