Archive for Flash Professional IDE

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.

Flex Challenges for Flash IDE Devleopers

A post recalled myslef got frustrated last September, after several weeks honeymoon turning into Flex from Flash.

No doubt some developers from Flex community not easy to understand what’s the meaning when a Flash developer complaining (AS3 === AS3) = false, as the majority of Flex developers do not know too much about development in Flash IDE. The feeling of ‘second class citizens’ for Flash developers in Flex development also could not make sense to some of them.

I would like to say, there’s no different AS3 language itself whatever Flash IDE or Flex, but the way of coding is wholly different and big changes for Flash developers when try to work with Flex.

Rapid application development

My favorite Flex blogger Yakov Fain had a Flex and Java book in 2006, Flex Builder was a ‘RAD tool’ in that book, but some months later, a new post said ‘Flex 2 is not a RAD tool‘ telling the real truth. He also questioned the usage of dominated Cairngorm framework for Flex applications. Despite of some questions like these, however, Flex development is target to RAD. Although even today, the question asked by bosses ‘how to make a complex Flex application fast, extendable, fast UI change, great usabilities for every components and views, largely reusable classes to fit for different structures, tested fully with agile methods fast and easily, less developers and hours’ still no one-fit-all answer, Flex teams are working the way into RAD at some percents.

The RAD nature of Flex making the big difference between Flash IDE applications and Flex applications, as Flash applications are more focus on Creative and User Experiences. Flash IDE projects are mostly like to be design-driven, with smooth workflow between designers and Flash IDE developers. While Flex application must largely adopt design patterns, restricted by components-base structure, agreement such as framework, patterns, coding style, between developers now and future.

Developing Flex applications, Flash IDE Developers have to learn more design patterns and structure frameworks, reading Flex SDK source code, get familiar with Flex components functions/events/behaviors, struggle with SDK bugs.

Design challenges

Early months before, I got impression from Adobe’s seminars/articles that, Flex framework is to give you a fast, powerful, extendable component-container collections, easy to change with CSS and bitmaps. And you can easily extend design with Flash IDE even. That’s not the truth in real world. That’s what talent Flash/Flex developer Jesse Warden talking about design challenges.

I used to have a former Flash IDE version of my Flex projects, everything could be replaced with Flex components except a creation task with script-based animations. I found it’s not too hard to move the code base from Flash project into new Flex application, and feel happy in the beginning. But later when my bosses asked me to change something from time to time, I got some pains the needs of strong-typed communication functions between Flex framework and that low-level UIComponent-extended Flash component, split my brain into two parts, one thinking in Flash another thinking in Flex.

Satisfaction

Most of workers working not only for money, but also for some sort of self-fulfillment, coming from satisfactions of his works. Flash IDE developers can get more or less satisfactions from Flash projects, where working with designers, whatever some sort of creatives and some sort of happiness.

Flash developers join into Flex projects will have less satisfactions. Each time when Adobe evangelist talking about how great a new Flex application is, someone will notice that ‘the best Flash applications in the industry still made with Flash IDE, not Flex’. Design challenges are limitations to make Flex to be satisfied like Flash applications, especially when designers have very limited experience working with Flex, even worse definitely no designer at all. Each time when the feeling comes, you ‘do not have the ability to make that happen which can be made with Flash easily’, can you feel it good?

Flex developers coming from Java or other languages getting satisfactions from Flex, as Flex applications he can build much beautiful than Java GUIs, HTML interfaces, and much easier. They’ve already have good experiences with enterprise design patterns, Flex is easy for them to dive into, and the results for them are amazing.