How to prepare yourself for Flash CS4 ACE exam

Just passed! I become Adobe Certified Expert on Flash CS4!

Like Flex with AIR certification I’d like to share my experience to prepare yourself for ACE exam of Flash CS4.

First of all… EXPERIENCE! You must work, play and work & play with Flash CS4 IDE and Actionscript 3.
More experience you have on Flash development less you must study for the exam and you have more chance to pass.

Obviously, it’s so difficult to know everything about Flash CS4 from all IDE controls to Actionscript 3 and OOP so there are 2 books that could be helpful to solve this “issue”.

With those book you can create a good base to try ACE exam for Flash CS4 but, if you have read Essential Actionscript 3 could be better for Actionscript side and for your daily work ;).
Another good suggestion is to read Help guide of Flash, in fact Adobe made an impressive job on that guide and you can find lots of interesting stuff; you can download a guide PDF file directly from this link.

Try everything, from import PSD or AI files to prepare files for web or desktop application with AIR, because you may find some questions about AIR and own code syntax!

Finally test yourself before real exam with a very good service (I really appreciate it) like acequestions.com with less then $10 you can try how Flash CS4 exam works and also which kind of questions you could find in that certification.
That’s it! Take a look at Adobe site to read all information to become Adobe Certified Expert and… GOOD LUCK!

Memento Pattern in Actionscript 3 (UNDO/REDO)

Happy new Year everybody!

I’d like to begin 2010 with a design pattern argument.

First design pattern of this year is Memento pattern, that could be very useful if you are working on an AIR desktop application or in a Flex RIA and you want to make an history of user’s actions.
In fact this pattern is used to make undo and redo in an application.

Memento pattern is tightly coupled with originator object and it’s usually composed by 3 different parts:

  • memento
  • caretaker
  • originator

Originator is object that pass data to caretaker and it saved them in a couple of arrays (undoArray and redoArray).
So caretaker is an object that stores a memento snapshot and, if originator needs, pass undo or redo data to this object.

I prepare a sample to understand better what could you use Memento pattern in your applications (“view source” option is activated).
I wrote a Memento class with a Singleton to centralize all users actions,then I create a MementoVO that is a dynamic class to help me store data from each object used by the user, you could use a simple Object instead of a dynamic class to save more memory if you prefer.
Sample is very easy but useful for Memento pattern purpose, in fact you can move windows trough the stage and our “history” class (Memento.as) saves their positions when saveAction method is called by the originator (an instance of CustomWin).

Memento class has 4 essentials methods that are:

  • undo()
  • redo()
  • saveAction(_obj:Object)
  • saveRedoAction(_obj:Object)

I start from the end, saveRedoAction, last method, is used to save the position of a window before I restore its positions, usually Redo action is used only one time, but if you want you could create an Array and work with multiple Redo.

Another important method is saveAction that is called when mouse down event was triggered and it stores in memento class own old position and object itselfs.

First two methods need to undo and redo an user action, it’s easy isn’t it?!

I think that in this year I’ll share lots of those patterns with you to share our knowledge together so feel free to add comment at this post and we could make an interesting and useful conversation, I’m totally sure!

Review of “Confessions of a public speaker”

I’m so happy to make a review of Confessions of a public speaker because it was an inspire book for me that gave me tons of tricks and confirmed feelings that I’ve when I make speech.

Scott Berkun, the author, is a young guy very passionate about his job, he had a great past working for big companies like Microsoft in IE team and not only.
He wrote great books like Making things happen or The Myths of Innovation, I read only the first one and it was very good.

In Confessions of a public speaker you can find everything that you need to grow your skills like speaker, in fact Scott describes own feelings during particular situation, he talks about how to manage crowd in a room and how to create a connection with people in your room and this is only the beginning…
With his informal writing he shares with us own experiences and a part of him, I think is the best way to teach how to grow like speaker but also like teacher.
He dedicates a chapter to explain different approaches between a teacher and a public speaker, I really appreciate a lots because I found similitudes trough Scott’s book and last course for trainers that I took part last year.
For a teacher and speaker like me this book is like a light in the hell that give me new motivations to do my job better and explain me how to prepare myself in a new way that could give me opportunity to make better speech and give to people more.

I suggest to everyone to have a copy of this book that you are a public speaker or an account of a company, it really help you to prepare better an important appointment and to create a connection with you audience.

Flickr mesh-up with actionscript 3, REST or SWX

Today I spend my afternoon to configure a part of a full Flash website that interact with Flickr and that retrieve data from my account without any appication authentication but only with my Flickr key.

First of all I was really impressed about how many languages you can use to bring Flickr photos and use in own desktop application or website (Real Basic, cUrl, Perl, Delphi, C…).

When you want retrieve photos from Flickr you must have a Flickr key that is totally free and you can activate one directly in the right section of Flickr site.
In the same section you can find whole documentation and lots of services expose to retrieve any kind of data from a photo, from Exif data to user or friends informations.
For AS3 we have a couple of interesting library; first one is as3flickrlib very well documented but it’s so long to start work with it because you must to find a frob ID then a token and finally you can start to work with Flickr API.
The other one is SWX, that is written by Aral Balkan and it’s too easy to mesh up any kind of popular service like Flickr, Twitter and so on.
Aral gives us availability to use SWX Service Explorer to take a look at the data and how to mesh up your application with public API, I really love it on Flash Lite too!

This is very interesting because you can retrieve all API in this library and in few line of code you can work with public services.
This is a simple example to call Flickr services with SWX, you can download source code too:

swx = new SWX();
swx.gateway = GATEWAY_PHP;
swx.encoding = "POST";
var callDetails:Object =
{
serviceClass: "Flickr",
method: "photosSearch",
args: ["", "", "#mart3"],
encoding: "POST",
timeout: 5,
resultHandler: resultPhotos,
faultHandler: faultHandler
};
swx.call(callDetails);

Another interesting way to work with Flickr API without any authentication is using REST API.
REST (Representational state transfer) is a very simple way to request data from a database, update, delete them or to create new record using HTTPHeaders and XML.
You must know that AS3 doesn’t have PUT and DELETE method but there are some libraries that create a workaround to solve this limitation and they work very well with REST (as3httpclientlib for example)
I start to approach REST a couple of months ago with Ruby on Rails and I think is amazing.

Flickr gives us REST API too, and you can see that is so simple create a Flickr gallery with REST and Actionscript 3.

We have some API that works without authentication like photos search and we use this service to retrieve data for our Flickr gallery.
First of all we take a look at service documentation on Flickr, you can see that we have a lots of opportunity to find data on Flickr; we can search photos via userID, tags, text on title or description and so on.

In Actionscript 3 we’ll use URLLoader class and prepare some url to retrieve XML data from REST.

private const FLICKR_SERVICE = "flickr.photos.search";

private const API_FLICKR:String = "c6c31464878505403f9bbbf6214ae413";

private const PATH_SEARCH_FLICKR:String = "http://api.flickr.com/services/rest/";

		

public function FlickrRest(){

			

	var varsFlickr:URLVariables = new URLVariables();

	varsFlickr.method = FLICKR_SERVICE;

	varsFlickr.api_key = API_FLICKR;

	varsFlickr.tags = "#mart3";

			

	var req:URLRequest = new URLRequest();

	req.url = PATH_SEARCH_FLICKR;

	req.method = URLRequestMethod.POST;

	req.data = varsFlickr;

			

	var urlL : URLLoader = new URLLoader();

	urlL.addEventListener(Event.COMPLETE, retrieveImages);

        urlL.load(req);

			

}

You can download source code and final sample from this link.
Finally I’d like to explain how to compose photo’s url to retrieve them on Flickr.
Flickr url is composed by some variables that you can find in REST XML or SWX result object

  1.  set FARM (ex.: http://farm”+flickrXML..photo[i].@farm+”.static.flickr.com/)
  2. set SERVER (ex.: +flickrXML..photo[i].@server+”/”)
  3. set Photo ID with underscore  (ex.: +flickrXML..photo[i].@id+”_”+”)
  4. set Secret code (ex.: flickrXML..photo[i].@secret+)
  5. last parameters is which size you want to get photos, you can use “_s.jpg” for small size, “_m.jpg” for medium, “_l.jpg” for large and so on.

I hope that could be interesting for many developers, if you have any suggestions or idea about mesh up with Flickr, feel free to drop a comment.

Flash, Flex and SEO

During the flight from Philadelphia to Los Angeles I read a book that I wait for long time and finally arrive a couple of months ago but I’ve never started to read before.

The book is Search Engine Optimization for Flash by Todd Perkins, the first that talks about this argument and also about how to make your Flex RIA searchable from spiaders, so I was so exciting before start to read.

My final impression is that you don’t need to read this book if you are a developer because there aren’t new things to do…
I can resume the book in those few best practices:

  • Use SWFObject because make your SWF file more easy to read for spiders
  • Use SWFAddress or URLKit to rewrite url of your page but it’s useful only for RIA or site usability, not for SEO because HTML is the same for all pages, change only the page url.
  • Avoid to develop a full flash site if you are interested to indexing your project
  • Remember to “talk” with spiders via META tag in HTML page
  • One of most important thing is to make a relevant title of your HTML page
  • With FP 10 you don’t make anything to indexing your contents (dynamic or static text) because spider navigate trough SWF file to retrieve informations
  • Remember that you can set XMP file for your Flash project but until now, search engines don’t use those informations

I think that’s all, I hope to find more about how can create searchable content with Flash (there is a good PDF file in adobe website) but I think that there is no way.
We are only at the beginning of a big mountain and I hope that Adobe starts to make something new in next few months… maybe at MAX 2009 also, but I really don’t know.

Presentation Zen: a book dedicates to speakers

This summer, during my flights, I decide to read a book dedicate on how to create AMAZING presentation, so I buy Presentation Zen and in 10 hours more or less I finish it and… WOW, it opens my mind!

Author approach is very simple and start his book saying: “Remember that are only suggestions, this book is not a bible that teach you how to use Powerpoint or Keynote, but it shows you how to approach a real presentation process”.

In fact, if you read the book, you don’t learn how to prepare great slides with slideware (it’s a fantastic term to define presentation’s softwares like Powerpoint or Keynote) but you’ll learn what you MUST think behind a slide… out of your computers world.

Few things that I learn reading Presentation Zen:

  • Avoid bullets list (like this :P)
  • Think about the message before switch on your computer and, if you can, go away from your computer with a pen or pencil and paper, tons of papers
  • You must focus your presentation in ONE MESSAGE and follow it during your slides creation
  • An image is better of 1 thousand of words
  • Presentation must help you during your speech and not substitute you
  • Less is better

There are tons of concepts that can help any kind of speakers from IT world to Yoga teachers (I suppose).

I think could be so interesting for anyone that usually speech for passion in conferences or for everyone that make presentation for work like CEO, marketing people and so on.
If you are interesting to buy this book or give more informations about it, go to author’s blog.

Create PDF in runtime with Actionscript 3 (AlivePDF, Zinc or AIR, Flex or Flash)

This morning I’ve a new target, create PDF in runtime with Actionscript 3.
Very cool project to accomplished this mission is AlivePDF, an opensource AS3 library that you can download from Google Code.
AlivePDF allow you to generate PDF in runtime with Actionscript 3 and you can add pages, draw in each pages or add images, it’s very powerful library.

In this sample I use Actionscript 3 (with FDT) and Multidmedia Zinc 3, but you can use Flex or Flash and AIR to make this sample.
So first of all I create a simple class that allow you to create a PDF file with multiple pages and to add content in each pages.
This is the code:

package org.mart3.pdfGeneration {
    import flash.events.Event;    
    import flash.utils.ByteArray;    
    
    import org.alivepdf.images.ImageFormat;    
    import org.alivepdf.saving.Method;    
    
    import flash.display.Loader;    
    import flash.events.IEventDispatcher;    
    import flash.events.EventDispatcher;
    
    import org.alivepdf.pdf.PDF;
    import org.alivepdf.layout.Orientation;
    import org.alivepdf.layout.Size;
    import org.alivepdf.layout.Unit;
    import org.alivepdf.display.Display;
    
    /**
     * @author lm
     */
    public class CreatePDF extends EventDispatcher {
        
        private var pdf:PDF;
        public var pdfBA:ByteArray;
        
        public function CreatePDF(target : IEventDispatcher = null) {
            super(target);
            
            pdf = new PDF(Orientation.LANDSCAPE, Unit.MM, Size.A4);
            pdf.setDisplayMode(Display.FULL_PAGE);
        }
        
        public function set totalPages(num:int):void{
                
            for(var i:int = 0; i < num; i++){
            
                pdf.addPage();    
                
            }
    
        }
         public function setData(_l : Loader, _numPage:int) : void {
            
            pdf.gotoPage(_numPage);
            pdf.addImage(_l, 15, 15, 0, 0, ImageFormat.JPG, 100);
        }
        
        public function savePDF():void{
            pdfBA = new ByteArray();
            pdfBA = pdf.save(Method.LOCAL);
            
            var evt : Event = new Event("baReadyEvent");
            dispatchEvent(evt);
        }
    }
}

Obviously if you want, you can create a custom event that pass to the document class the ByteArray but this is a quick sample to show how you can create PDF in runtime!

One of the amazing things that you should do with AlivePDF, it’s that you can decide to save PDF locally or on web! Read documentation because it’s very interesting what you can do with this library!

Ok now, go to document class where we use MDM swc that you can find when install Zinc on your computer (you can find 2 differents SWC, one for Flash and the other one for Flex. Remeber also that Flash SWC works with Flash CS4 also, not only with Flash CS3!).
In this class we do those simple steps:

  • create a PDF object using CreatePDF object
  • set our PDF document
  • pass an external image loaded with Loader object
  • save PDF bytearray with Zinc FileSystem class
package org.mart3.pdfGeneration {

    import flash.display.MovieClip;    
    import flash.net.URLRequest;    
    import flash.display.Loader;    
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;

    import mdm.*;

    import org.mart3.pdfGeneration.*;

    /**
     * @author lm
     */
    public class Main extends Sprite {
    
        private var pdfObj:CreatePDF;
        private var l : Loader;
    
        public function Main() {
            
            mdm.Application.init(this);            
            
            pdfObj = new CreatePDF();
            pdfObj.totalPages = 2;
            pdfObj.addEventListener("baReadyEvent", saveLocalPDF);
            
            l =  new Loader();
            l.name = "myImg";
            
            l.contentLoaderInfo.addEventListener(Event.COMPLETE, showImage);
            l.load(new URLRequest(mdm.Application.path+"assets/bg.jpg"));
        }
        
        private function saveLocalPDF(e:Event) : void {
        
            mdm.FileSystem.BinaryFile.setDataBA(pdfObj.pdfBA);
            mdm.FileSystem.BinaryFile.writeDataBA(mdm.System.Paths.desktop+"generate.pdf");
    
        }

        private function showImage(event : Event) : void {
            
            l.scaleX = l.scaleY = .4;
            var mc : MovieClip = new MovieClip();
            mc.buttonMode = true;
            mc.addEventListener(MouseEvent.CLICK, savePDF);
            mc.addChild(l);
            this.addChild(mc);
        }
        
        private function savePDF(event : MouseEvent) : void {
            event.currentTarget.alpha = .5;
            pdfObj.setData(l, 1);
            pdfObj.savePDF();

            
        }
    }
}

You can also download source files from their hosting service and test it on your computer.
Feel free to give me any comments about AlivePDF, it’s very interesting to know what you think about this AS3 library.