
Make ActionScript Design Patterns Mobile
Gentle Readers: This is the second part of a post on using ActionScript in a mobile environment by our guest blogger, Christian Peters who maintains a blog at http://digitale-avantgarde.com. He was kind enough to translate his post from German into English. (For those of you who would prefer the original German version, visit Chris’ site.) Because of the size of the post, we’ve had to divide it into two separate posts. The first half of this post is can be found in the previous posting. We and Chris would appreciate your comments.
Registering Mediators
If you look back at our ViewNavigatorApplication at the beginning, you’ll notice, that I’ve added an initial view:
1. firstView="com.digitaleavantgarce.view.components.HomeView"
This is the first view and the ViewNavigator sets it as the active view at the beginning.
I’ve moved it from the default package to a package that is more compliant to my overall structure.
It can be any view you like, but let’s say it has a button with the label “Click me” in it. It should read something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| 1. <s:view xmlns:fx="http://ns.adobe.com/mxml/2009"
2. xmlns:s="library://ns.adobe.com/flex/spark"
3. initialize="onInitalization(event)"
4. title="Getting Started">
5. <fx:script>
6. < ![CDATA[
7. import mx.events.FlexEvent;
8.
9. public static const NAME:String = 'HomeView';
10. public static const CLICKED:String = NAME+'Clicked';
11.
12. protected function onInitalization(event:FlexEvent):void
13. {
14. this.id = NAME;
15. }
16. ]]>
17. </fx:script>
18. <s:button label="Click me" horizontalCenter="0" verticalCenter="0" click="dispatchEvent(new Event(CLICKED));"/>
19. </s:view> |
This should be familiar, but note two things:
First: Since the View does not have a name Property and I don’t want to implement an interface, I make sure that the id is equal to the NAME constant on initalization!
Second: When the button is clicked, it’s dispatching an event named CLICKED. Remember, that the views should not host logic, they just should forward the action to the framwork. Thus, a mediator should take care of the action.
Read more…

Optimizing Mobile Apps with Design Patterns
Gentle Readers: Every now and then Chandima and I have a guest post. In this case, Christian Peters who maintains a blog at http://digitale-avantgarde.com was kind enough to translate his post from German into English. (For those of you who would prefer the original German version, visit Chris’ site.) Because of the size of the post, we’ve had to divide it into two separate posts. The second half of the post will be available next week. We and Chris would appreciate your comments. Click the download button to get the entire code:
PureMVC Goes Mobile
Let’s build a cross-platform compatible, MVC-driven & ready-to-compile Mobile Application with the Flex Framework!
A year ago, finding people who bet serious money on Flash missing a connection to the mobile world was an easy task. This is no longer the case nowadays. Adobe has introduced an iOS Compiler and AIR for Android & Blackberry Playbook. With the latest release of Flex SDK 4.5.1, the average Flash-Coder is transformed to a crossplatform-ready mobile developer. Amazing times. Let’s look at how to adjust the Standard Port of the famous PureMVC Framework to be mobile-ready! The Flex SDK ships with an integrated Navigation for Mobile Views, the ViewNavigator. There is an excellent introduction to the topic, that can be found here, but I’ll give a brief overview about the concept:
Mobile Applications – especially on Smartphones – are restricted in a very important feature: Space. If you adapt a Web app to mobile, you’ll typically have much more views because you have to present the same content on smaller displays. Flex comes to the rescue by introducing the ViewNavigator. The ViewNavigator is a container, that holds references to the available views and makes navigation between them easy. You can imagine it as an array – where the view at the zero index is visible & active. It’s not a coincidence that the ViewNavigator has array-esque methods like popView() or pushView()!
The ViewNavigator is a nice way to handle views, because it’s an easy way to navigate through an app: Every view holds a reference to the ViewNavigtor – the navigator property – and can forward the application to another view on demand.
Well, it’s not all roses with the ViewNavigator! A view has its own control-mechanism as property – while it should be vice versa. Another downside: The registering and instantiation of views are becoming tasks of Flex, while you normally want to handle those tasks in your infrastructure framework of choice! Mine is PureMVC. I want to show you a way to hook PureMVC to the registering process of the ViewNavigator to build nicely decoupled applications for the mobile world. Some experience with PureMVC is recommended, but I’ll give you a quick …
Read more…
Although it may be a small conceptual leap for someone who has experience with the single-core version of PureMVC to visualize how multicore works, it can be a little daunting for a novice. This post describes the design and development of a simple game concept to exemplify the utility of PureMVC multicore. This is a pure AS3 app that doesn’t use the Flex framework. You can download the source and build the app in Flex/Flash Builder (as an AS3 project) or Flash CS3/4.
The basic difference between single-core ( now known as the standard version ) and multicore is that multicore allows multiple MVC triads (multiple cores in PureMVC parlance) to be embedded inside a single application. The general recommendation is to use PureMVC multicore for all projects as it affords a lot more power in terms of developing modular applications and unit testing. However, developers who are new to PureMVC should first develop a simple single-core application first to get familiar with the framework. My previous PureMVC post describing a minimalist example will get you started with the basics. From here onwards, I’m assuming that you have a basic understanding of how the standard version of PureMVC works.
Read more…
Recent Comments