Flex SDK 4.5 mobile roadmap

I was certainly very excited about the new SDK regarding to mobile development. Lately many clients ask about mobile support for their applications and slowly all projects become multi target (web, local, tablet, mobile) This imply a difficult migration, running around some CSS magic or even writing versions in Objective C to target IOS platform.

File->Create new me

 

So is possible to develop once and deploy to any target? Well, not really, but with a good design, we’re almost there. The new SDK can target Android devices in his debut, and promise to support IOS devices (via cross-compiling to Objective C) and Blackberry Playbook in the near future (update in June … or probably is a fact when you read this)

 

Wizard to create new Mobile Project

Wizard to create new Mobile Project

Wizzard to create Mobile Project

The process is straightforward: you need to create a Flex Mobile Project or an ActionScript Mobile Project from the File menu and a wizard will help you target the correct device. As stated, currently only Android devices are available, but the concrete model doesn’t matter since you can change device target at any point (always inside Android family with version 2.2 Froyo at least) About UI there are a couple of mechanism that helps in adequate to the different screens and resolution:

- You should constrain or your containers, say a List, to keep a certain distance from borders instead of give a fixed size, this ensures an adaptable layout
- There’s a multi DPI mechanism to adapt to different screen density trough rescaling (typically 160, 240 and 320) so your UI remain the same. For bitmaps you can use the MultiDPIBitmapSource tag to provide different graphics for each

There are a few foundation components to navigate applications: View based application (default) and tabbed based application. The first one use a stack of screen to push and pop different applications screens, creating and destroying them on the fly so memory consumption doesn’t growth. Since screens are destroyed on demand, data persists because the application could be interrupted at any moment (because a call i.e) and you should be able to restore at the same point, or go back to a previous screen. Data is injected as the data property at any view. Tabbed applications works similarly, but instead of scrolling from screen to screen, you just tab between them.

Here’s a sample code of the Twitter Trends demo, showing the initial application template

<?xml version="1.0" encoding="utf-8"?>
<s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" firstView="views.TwitterTrendsHomeView"
persistNavigatorState="true">
  <s:actionContent>
    <s:Button id="refreshBtn" click="Object(navigator.activeView).refresh()">
    <s:icon>
      <s:MultiDPIBitmapSource source160dpi="@Embed('assets/refresh160.png')"
      source240dpi="@Embed('assets/refresh240.png')"
      source320dpi="@Embed('assets/refresh320.png')"/>
    </s:icon>
  </s:Button>
 </s:actionContent>
</s:ViewNavigatorApplication>

Another important thing to remark is that mobile aware components were updated to perform smooth on mobile devices, and in this sense should be considered “light” components, while web components are more resource intensive consumers, so are not a good choice for mobile apps. Articles emphasize in simple skins and programmatic itemrenderers (based on ActionScript, not on MXML) to gain a better performance.

Finally some thoughts about architecture. If you want to develop once and deploy to multiple target you can do … partially. All the business and services domain can be the same, but view will change between different targets. So suppose you want to have your web application available for mobiles, you can follow some MVP or MVC pattern (Model-View-Presenter or Model-View-Controller) so View related code keeps on each project, while data, business and services access can be shared. Almost all of the traditional Flex frameworks emphasize this structure, and if you follow some of them probably will not be difficult to adapt to this structure (if not, read flex frameworks)

To start on this topic, Adobe have many articles and examples, you can begin reading about the topics commented here but more in deep reading a mobile reference or check a list of examples as a basement for your own. We’re planning our own example very soon, so stay tuned.

Posted in Flex | 2 Comments

Flex SDK 4.5 is out!

Finally Flex SDK 4.5 leaves the beta state and was officially released with all the CS5.5 package. Changes are not major like in the transition between Flex 3 and Flash Builder 4, but it adds important features. First of all, the Datagrid component was moved to Spark namespace, probably one of the most used components when dealing with data. Other components like Image or XXX was moved as well, having more elements to choice in the goal of having a Spark only application. Anyway that’s not posible since a lot of elements are still in the Halo namespace whitout his Spark counterpart (Viewstack or the Charting elements) so coexistence will be still the rule.

Flash Builder 4.5

Another exciting feature is the Mobile templates (for Android and IOs), that allows to create projects with a mobile profile, so you can target different devices around there. This opens a wide field to Flex developpers, building at the same time for web and mobile. Anyway you probably can’t reuse the same, since many components are very intensive in resource consuming and not the best for a restricted environment like the mobile platform. Will be true the phrase “one development, many targets”? Only partially, but we will write about this when testing the mobile profiles.

Another thing to note, specially for those moving Flex 3 applications to Flash Builder 4, and now to 4.5 is that some deprecated tags are not anymore supported (in example verticalAxisRenderer for charting) so instead of getting a warning, you get a compile error that prevents you to further go. For those wondering to move to Flash Builder 4.5 standalone application adding SDK 4.1 as a compile options, take into account that you can’t switch to design mode so are constrained to code-only view if you set SDK 4.1 for compile options.

code

There’s a special version for PHP developers that integrates with Zend server. Also Flash Builder adds the feature of code snippets, where you can add your favorite code to insert with just a couple of keys. In adition with code completition and autogeneration of handlers, the code editor is much more powerful and profesional

So welcome Flash Builder 4.5 and stay tunned, we will be doing some test around the new version, specially for mobile profiles

Posted in Flex | Leave a comment

Swiz demo application

You can download the demo application as fxp file (Flash Builder Project) from here
You can see the running application here (select framework you’re working on for multiple choice)

Swiz is an Inversion of Control/Dependency injection based framework that keeps application code decoupled. It has a clear inspiration in Spring framework, and load services from beanProvider where you declare all non visual elements

Dependency injection

Dependency injection

The injection is done using an [Inject] metadata, here’s an excerpt of our demo app, that point to a property of our Model

[Bindable]
[Inject( source="appModel.currentQuestion", bind="true", twoWay="true")]
public var quest:Question;

Swiz dispatch Flex standard events and use metatags to handle them, here’s an example from our demo app

[EventHandler( event="UserEvent.LOGIN_USER_REQUESTED", properties="user")]
public function loginUser( user : User ) : void

This handler receives a LOGIN_USER_REQUESTED, but you can manage a whole set of events in a single handler

[EventHandler(event="QuizzEvent.*", properties="question")]
public function saveAnswer(question:Question):void

When a non-visual component need to fire an event, you can add [Dispatcher] metatag

[Dispatcher]
public var dispatcher : IEventDispatcher;

For services Swiz offer a ServiceHelper class that automatically creates a AsyncToken to set a result and fault handler, here’s an example:

[EventHandler( event="UserEvent.SAVE_USER_REQUESTED", properties="user" )]
/**
* Perform a server request to save the user
*/
public function saveUser( user : User ) : void
{
serviceHelper.executeServiceCall( userService.saveUser( user ), handleSaveUserResult );
}

The handleSavedUserResult will receive the result of the saveUser call

Event Mediation Schema

Event Mediation Schema

Sumarizing
The most common features of Swiz are Dependency Injection, Event Handling and Server Interaction. Swiz use metatags to handle most common tasks (Injection, EventHandler, Binding, Dispatcher) plus a beanProvider where you declare non visual components that should be injected by the framework. Also Swiz offer handy tools like MockDelegateHelper to simulate server side calls and arbitrary custom tags that you can declare for any purpose (Swiz 1.0)

Now let’s take a look at our test application.

Multiple choice using Swiz

Principles and quick start is well documented at http://swizframework.jira.com/wiki/display/SWIZ/Home , where also advanced topics like TestCase, module support and best practices are covered. With a single review I could write our Multiple Choice without much trouble. Here’s a quick review of the structure and how the things were done:

Typically steps to setup a project are:

1. Add compiled framework to the project
2. Declare in Beans.mxml all the non visual main class
3. Use some PresentationModel (or more than one) to manage views and some Controller (or more than one) to manage inputs
4. Add views as needed injecting reference to data model and binding elements
5. Setup auxiliary models (questions and users in this case)
6. Setup services and events
7. Check injection, binding and event handlers trough your application, this is the mechanism where data flows

Highlights

Controller, models and services
- Declare controller, model and services in Beans.mxml. Here you should declare all the non visual stuff for injection.
Views
- The main application is splitted in three views for login, the quiz itself and the results, each one having his mxml in View folder
Models
- The Presentation Model manages the states trough the selectedView. The presentation model is declared in Beans as mainPresoModel
- The questions are loaded from an XML file in QuizModel declared as appModel in Beans
- User class store user related data, while Question encapsulates the questions itself (both in model folder)
Controller
- UserController manage the user interaction, I find handy that you can use wild cards to handle different kinds of Events from a single handler. My goal was to add a timeout, so saveAnswer method handles USER_SELECTION and TIME_OUT, but didn’t success on dispatch the event from the ClockProcessor
Custom metadata (new to Swiz 1.0)
- The custom metadata processor I have find is handy for declare your own tag and relate to your class, this allow a flexible approach.
Mocks
- The MockDelegateHelper was also a great utility to create my stub, and in combination with louse coupled classes (due to the injection of dependency) I guess Unit testing is much more easy. Also the library includes an AutowireTestCase to build testing, nice!
- In the results view I bind the User data to show statistics. Couldn’t access my ClockProcessor to get time (should review dependency) but I pass along as timestamps in Questions
- When using Binding and Injection, using an object property instead of the whole instance was a novelty

Reference URL for further reading: http://swizframework.jira.com/

Posted in Flex | Tagged , , | 1 Comment

Flex frameworks

Goals

This a small serie featuring available frameworks in Flex. The main idea is to read documentation and write right away a small Multiple Choice application using each of the frameworks.
Probably you think this is a crazy approach, since frameworks needs some time to study and leverage your skills. But the goal is different and point to this questions:

- Is the framework easy to understand as a whole picture?
- Is documentation enough for a quick startup?
- Is there any tool/template to follow right away?

Here are our topics (in alphabetical order) :

There are probably some others around (and some others to arise) but this cover some of the most used when this article was writen.

Test Application

The test application we will build to test each of the frameworks is a simple Multiple Choice. This multiple choice will load its questions from an XML file and automatically will adjust itself for showing N questions. Also a timer (not mandatory, but to capture time and give a sense of speed) is visible. We will simulate a login into a database so we can simulate server side interactions, something very common at development stages. Screens are:

Login Screen

Login Screen

Quiz Screen

Quiz Screen

Result Screen

Result Screen

So the user should login to enter the application (any user/pass will fit, we’re only simulating back-end services), then answer multiple choice questions … when finishing, a result screen will show final results

Topics

Each chapter will focus on a framework and illustrate trough the multiple choice following this information:

  • Short description of core elements
  • Demo quiz application using the framework
  • Conclusions (as highligths)

Disclaimer: I have used some of the frameworks at some extent, but will do my best in trying to recall my first impressions …. Also since this is a quick-read-and-use approach, probably I miss at some point some of the best practices, or even some approach from other framework translates to the new right away. If you’re confident with some of them, please post some coment to help enhance the experience.

Ok, enought for an introduction, let’s move to the first one: Swiz

Posted in Flex | Leave a comment

Welcome to the new Homepage

We’re improving our site, adding new content and changing the Homepage to something more easy to update than our old flash-based entry page. It’s funny: a site related to Flash don’t use Flash anymore in the Homepage, but things changed since 2001, when this site was launched. Today we use Flash where flash is needed, and we don’t think anymore that Flash is th best choice for everything. We believe that RIA (Rich Internet Applications) is a field where Flash shines, and the same for video or animation, but plain text like the one you’re reading now is fine with HTML.

We hope you continue supporting our effort, since this site is not commercial and all the material here was writed by people that want to share his knowledge.

Welcome to the new Flash-db homepage !

Posted in General | 4 Comments

Flash Media Server, Wowza and Red5

By: Jorge Solis

Recently I was involved in a discussion about multimedia servers for a game some friends are developping (dotGaia Fleets) and thanks to that discussion, arise this short comparision between the major multimedia server that exists for Flash and Flex: Flash Media Server, Red5 and Wowza. I have worked with all of them, so this is more my working experience than an exhaustive analisys.

Red5, Open Source, free, Java

Red 5

Red5 have a winner argument: is free an open source. This characteristic makes this server the ideal choice for any project in early stages (first testing and modelling) Before you make any choice, you can have something running at a very low cost, and those involved in startups could consider this as a great benefit.
I have used it for broadcasting and socket server with good results, but with some problems for sync between audio and video when recording live. Another problem (key for me) is certain lack of documentation and articles. If you go trough the tutorials that you can find around they cover all the basics (audio and video setup, login, NetConnection and NetStream handling, etc) but as far as you go in more complex scenarios (distributed broadcasting, chain of servers, balance based on ping time, etc) you will need to deal to Java source code, and that will be a challenge (specially for those like me not familiar with Java coding)
There are a few tools you can use to help in your development. Basically any text editor is fine to write code, the XML needed for basic setup or any java code to be deployed. There’s also some debugger an admin panel that recall the one for Flash Media Server and runs smoothly.
Another problem I faced was to find a hosting. Since there are a few, if you need a scalable environment or a CDN you’re in trouble, since the most important CDN (Content Delivery Network) in the market use Wowza or Flash Media Server. The lack of support is also a problem, but recently you can contact red5 developpers and get permissons to create tickets in red5.org site. Scalability is a key for medium to big applications, and as far as you add users, transference and distribution becomes the heavy elements when you need to pay the bills, beeing license a minor item in the equation

Wowza, an interesting alternative

Wowza
Wowza was made by people from the Adobe FMS team that begins his own company, and use also Java in the server side. In this aspect is similar to Red5 and you need to take into account that each time you change your application you need to redeploy and reinit the application. In Wowza you can restart the application whitout problems but in Red 5 I remember to restart the whole server … but there was more than one year ago, so probably currently you can restart the application fine. For those not coming from the Java World, the proccess of redeploy and reinit is slow and tedious at some point, so probably you want to test a batch of change instead of add step by step if time matters.
Wowza have interesting settings for bradcasting audio an video. In example, the XML for the application support a quality a type of stream tags extremely easy to add, specially because documentation is very complete and in Wowza forums you can find easy examples but also more sophisticated ones, with experience people that allways can give you a hand (they help me alot, big thanks)
You can use Wowza in combination with Amazon EC2 Cloud, and there are also some CDN based on Wowza. When looking at this services, pay atention about the avaibility of using server side scripts or not, some of the cheaper offers doesn’t allow to write and deploy your own modules, beeing a no go for more complex applications. Also you can consider an hibryd schema: static server for delivering and a dedicated server with full access for the buisiness layout. The question is: do you really need real streaming? Sometines just serve files in the standard way with an appropiate buffer is enought, and by far, cheaper.

Flash Media Server

Flash Media Server
And finally mi favourite, Flash Media Server. Many people arguee that the server license is expensive … and really is (around u$s 4000 a pro license) … but you really want to manage your own server?
And here is the real diference: if you want to host your streaming server (I mean put your dedicated server in a NOC) the license cost is a big deal, but if you think about it and select any of the available hosting or CDN, then license becomes a minor item compared to transference and avaibility. And really the big cost is transference. If you did run any stream based service and did pay your bills, probably you will agree with me. Also FMS have alot of services available including CloudFrontStreaming from Amazon, where you paid only for the transference (but you can’t add customized seever side scripts)
I will give some numbers as example: a basic hosting for development (up tp 10 simultaneous users, limited transference, ideal for client showcast) around u$s 10 month, a more stronger server, based on transference and simultaneous conections, between u$s 100/300 per month. My numbers are based on Influxis, the provider I use lately, but there are other similar networks as VitalStream or the expensive Akamai. In Stefan Richter Flashcomguru web you can find a very complete list
Technically FMS is probably the better known server, with ton of articles in Adobe Devnet
As a short list I will mention: admin panel, Javascript 1.5 as the server side script (so much more friendly to an ActionScript developper), application reload fromn the Admin panel, scalability and fail recovery based on Master-Edge servers, DRM (Digital Right Management) for licensed material distribution, dynamic streaming and detailed documentation.

For challenging development, probably the best choice, but the decision is up to you

Conclusion

One of the best books for reading about Flash streaming is “Programming Flash Communication Server”, with complete examples and the best set of examples never writed. Is a little old (2005) and the code is in AS2, but I never find another book with the same depth of concept (and I have read a lot), so if you really want to work on this, is a must read book. It includes a couple of little frameworks and an overview of the FMS AS2 components (that probably you never want to use, hehe)

Tip for arquitects: With an adequate multiuser logic encapsulation (say a good proxy), you can move from one to another server whitout much panic. .

Another one: You always need to evaluate if real streaming is neccesary in the project because is by far the more expensive item. If you can use static files with standard servers (progressive streaming) even in an hybrid environment (say one streaming server + many standard servers) your costs will become sustantially lower

Posted in General | 1 Comment