Think different?! NO… but maybe…

I want broken my silence about Apple vs Adobe “war” and share with you my thoughts.

It’s an hot topic and probably not all people will be agree with me but I feel to tell you my point of view.
First of all, today we are sure that Adobe will not invest anymore on iPhone packager for Flash CS5, so from a developer point of view I’m totally agree with Mike Chambers and Adobe too.
Android is a really amazing mobile OS not only for smartphone but also for MID, I saw on a Nvidia Tegra 2 and performance were really impressive.
I had an iPhone a year ago and now I’ve a HTC Hero with Android, guys believe me, it totally changes my life, everytime I say: “Android takes best features of Blackberry, iPhone and Nokia in one OS! Oh yes… phone calls work on Android :P”.

I saw AIR 2 and Flash Player 10.1 on Android in action during 3GSM in Barcelona and … WOW, Adobe is working very hard on that technologies and I test a Flash website not optimize for mobile on FP 10.1 and it works very well.
Future on Android will be very cool for every Flash Platform developers… but…

I’m also owner of a company and I know a little bit my customers or potential ones and if you talk about iPhone or Android they feel an app or game in different way.
I think the big problem is that few people known the powerful of Android OS and Google is not advertising so much it.
People that use Android after iPhone they don’t come back again, they are so happy about OS but if you take a look at carrier’s advertising they prepare great iPhone campaign but I didn’t see any Android campaign or carrier’s advertising dedicated to Android phones.
Adobe made a good job with iPhone packager and Apple close doors to it, if I see from point of view of both I could think that Adobe didn’t develop anything for iPhone and will not do that in the next future, Apple lose tons of possible applications in own store but they preserve their ecosystem, and freelances or IT companies?! Did you ever think to them?!

We are in a particular market moment where everybody is seeking a new way to make business or to invert the trend, those strategies could be useful in 80’s or 90’s not in 2010! Customers are not so happy to bring a company that make an iPhone app, another one for a RIA on web, another for a desktop apps and so on, or maybe one big company that make all but ask tons of money that there aren’t in this historical moment!
Lots of companies and developers were waiting for this new marketing possibility and probably, this possibility could create a win-win situation for everybody.
Companies and developers work more and have new possibilities to make business in a particular market moment, Adobe would be the first company that introduce in the market a technology that is real cross-platform, with AS3 I can develop on web, mobile, desktop apps and so on; probably many people upgrade to Flash CS5 only for iPhone packagers so they have a high ROI; finally Apple would have tons of new developers that will buy their products, probably approach Objective C maybe only to take a look but they will approach it, and they gain more revenue from the store… so everybody win nobody lose.
Probably it’s a poor point of view from a little man, but a win win situation could help in this moment…

I spent a couple of days to understand what is happening between Adobe and Apple but I think that nobody could know and nobody tell us the truth.
For now we can only wait and change our marketing strategy focusing on Android devices, maybe a day we could count more in big companies decisions… or maybe not…

Observer Pattern Actionscript 3

One of the most useful design pattern when you don’t want to work with framework like Swiz, Cairngorm, Mate or PureMVC but you’d like to work with a comfortable utility to manage events in your application or web site is Observer Pattern.

The definition from Wikipedia is:

The observer pattern (a subset of the publish/subscribe pattern) is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. It is mainly used to implement distributed event handling systems.


For more information and if you want to see UML diagram, take a look at wikipedia site.

You can use this design pattern when you want to notify to all object that are interesting in a particular notification; for example if you have 100 buttons you can show or hide only even or odd ones; it’s not important where they are added, if in the same displaylist or in another one, because it’s observer pattern that substitute event handling to notify something.
If you think how you usually work with event handling you must know where is situated your component  and if it’s nested in 10 different containers you must dispatch that event trough each component… it’s totally crazy!

Observer Pattern solve this problem because it’s like an event engine where knows all object that could be interesting in a notification and it notifies to all components.
When you start to work with it, you could use everywhere in your productions, believe me!

So how Observer Pattern works:

First of all you must create an Interface (IObserver) that has an update method that will be called from Observer manager when a notification will be called:

public interface IObserver {
    function update(_notification:String):void;
}
Then you must have an Observer Manager that manage all objects that implements IObserver interface.
This manager will have 3 public methods: subscribe, unsubscribe and notify.
You call subscribe when you want to add an object that is update from Observer; unsubscribe when you remove an object from a displaylist or if you don’t need to update anymore  and notify when you want to notify something to all subscribed objects:
public class ObserverManager {
private static var instance : ObserverManager;
private var observerData : Array;
public function ObserverManager():void{
observerData = new Array();
}
public static function getInstance() : ObserverManager{
if(instance == null)
instance = new ObserverManager();
return instance;
}
public function subscribe(observer:IObserver):void{
observerData.push(observer);
}
public function unsubscribe(observer : IObserver) : void {
var totObs:int = observerData.length;
for(var i:int = 0; i < totObs; i++){
if(observer === observerData[i]){
observerData.splice(i, 1);
break;
}
}
}
              
       public function notify(_notification:String):void{
var totObs:int = observerData.length;
for(var i:int = 0; i < totObs; i++){
observerData[i].update(_notification);
}
}
}

Ok now you are ready to work with observer, so we create an object that implements IObserver and another one that add on displaylist all IObserver objects and notify to all some notifications:

custom button that implements IObserver interface:

public class ObserverButton extends Button implements IObserver

{

	public static const HIDE_BUTTON:String = "hideBtnEvt";

	public static const SHOW_BUTTON:String = "showBtnEvt";

		

	public function ObserverButton()

	{

		super();			

	}

		

	public function update(_notification:String):void

	{	

		switch(_notification){			

			case HIDE_BUTTON:

				this.alpha = .2;

				break;

				

			case SHOW_BUTTON:

				this.alpha = 1;

				break;

		}			

	}

}

subscribe some custom buttons to observer manager:			

protected var observer:ObserverManager;

protected function init():void{				

	observer = ObserverManager.getInstance();

	for(var i:int = 0; i < 100; i++){			

		var btn:ObserverButton = new ObserverButton();

		btn.label = i.toString()

		addElement(btn);




		if((i & 1) == 0)

			observer.subscribe(btn);

					

		btn.x = Math.random() * 800;

		btn.y = Math.random() * 500 + 70;

					

}

That’s it! You can see the Flex 4 sample that use Observer Pattern here (with right click you can see and download source code).
If you have any questions or suggestions feel free to leave a comment.

Working with zip files and Flash Platform

In our last Flash / AIR project we are working with tons of automations to create files, save them on computer, download files from the web and so on.

A library that I think could be interesting not only for us but also for other people that will work with zip files is FZIP from codeazur.

I saw it a couple of years ago and finally I used it, I think it’s so cool for your desktop or web projects based on Flex, Flash or AIR.
Working with FZIP is so easy, if you want to add a file into a new zip file you only write:

var zip:FZip = new FZip(); zip.addFile(f.name, f.data); //f is a File object instance

You can also set a particular position for your file with addFileAt method, remove a file, read each file and working with it without using any different language; all with Actionscript 3!

When you are ready to create your zip file you can save it with FileStream object like this:

var ba:ByteArray = new ByteArray(); zip.serialize(ba) ba.position = 0; var finalZIP:File = File.desktopDirectory.resolvePath("AIRZIPPER.zip"); var fs:FileStream = new FileStream(); fs.open(finalZIP, FileMode.WRITE); fs.writeBytes(ba); fs.close();
So easy, isn’t it?!
One of the main thing that could be interesting to know about FZIP is that library doesn’t read zip file with data descriptor like you can read on official website in Limitations paragraph:
FZip generally can’t read ZIPs that make use of Data Descriptors. Examples of such ZIPs are those created by the Mac OS X Archiver utility, SWCs, JARs, etc.
So to solve this problem I made a simple AIR application that zip your files (only files for now but soon I also work with folders and subfolders) and give a perfect zip file without any data descriptor, so you can use to work with FZIP lib.
You can download it for free from this link (I think they are on dedicated servers), I hope that you enjoy it and if you have any requests feel free to ask me via email or adding a comment to this post!
UPDATE
I’ve just received a mail from Claus of codeazur that gives me a new repository for FZIP where they solved data descriptor issue; thank you Claus!