Category
Recent Posts
- Smooth Zooming Depends on Flash Version
- Covert Actions
- Transform SWF 3.0.1 now available
- Considering A Move To Memphis
- Well, It Took A While
Archives
Search Box
Meta
Hard To Port?
Posted by smackay | Filed under transform
Quick question: Is porting an application from Transform 2.3 to 3.0 difficult?
Quick answer: no.
With the upcoming release of Transform SWF 3.0 on Sept 15th it was time to move all the existing Cookbook examples over to use the new code. The process was surprisingly easy, though a little tedious, so that bodes well for anyone upgrading any existing applications.
The major changes in Version 3.0 were essentially structural and general cleanup rather than “semantic”. There is still a one-to-one mapping from the data structures in the Flash File Format Specification to classes in Transform. The classes are still essentially Java Beans that know how to encoded and decode themselves so the new version will be familiar, if not quite identical. Some of the changes, major and minor which affect porting existing code include:
- Shorter class names. The “FS” prefix (a hangover from the original Objective-C code written a very long time ago) is gone and tedious to use names such as SetBackgroundColor, FSPlaceObject2 and FSRemoveObject2 now become the slimmer and fleeter: Background, Place2 and Remove2 respectively.
- Fewer constructors for classes with optional fields. Instead of having constructors for every combination of optional fields, with FSPlaceObject2 being the canonical, bloated and easy to misuse example, now the classes are their own Builders. Typically there is one constructor and the set methods return the object allowing several calls to be chained together. For example, creating a ShapeStyle used to be:
new ShapeStyle(1, 1, 0, 0, 0)now it is the much more readable but slightly verbose:new ShapeStyle().setLineStyle(1).setFillStyle(1).setMove(0, 0) - Movie objects used to maintain a counter used for generating unique identifiers for definitions. This is no longer the case and applications have to maintain the counter themselves. This means that calls such as:
DefineMovieClip clip = new DefineMovieClip(movie.newIdentifier(), new ArrayList());are now replaced by:int uid = 1;
...
DefineMovieClip clip = new DefineMovieClip(uid++, new ArrayList()); - Integer constants are replaced by enums, e.g. the codes representing compound events for movie clip event handlers are now replaced by the Event enum and multiple events are represented with EnumSets.
- Immutable classes make for fast copying of the parent object, so all actions and basic data types such as bounding boxes, coordinate and colour transforms are now immutable. Constructing immutable objects with multiple values, e.g. the Push NewFunction[2] actions and all Filters now employ special Builder classes:
Push.Builder builder = new Push.Builder();
builder.add(integer).add(string);
actions.add(builder.build()); - New Factories and Service Providers. The utilities classes that were used to generates the objects representing images, sounds and text were refactored to follow the Service Provider pattern. This was the biggest structural change, though the impact on existing code is relatively minor. For example creating the definition for an image was:
FSImageConstructor imageGenerator = new FSImageConstructor(imageFile);In the new version this becomes:
FSDefineObject image = imageGenerator.defineImage(movie.newIdentifier());final ImageFactory factory = new ImageFactory();
factory.read(new File(imageFile));
final ImageTag image = factory.defineImage(uid++); - Movie is now strictly a container. The fields such as version, signature, frameSize and frameRate are now part of the new MovieHeader class. This change was designed to make it easier for people to write their own decoders and to be consistent with other meta-data objects such as MovieMetaData and MovieAttributes since it was not practical to move everything into Movie. For example:
FSMovie movie = new FSMovie();Now becomes:
movie.setFrameRate(1.0f);
movie.setFrameSize(new FSBounds(-4000, -4000, 4000, 4000));
Movie movie = new Movie();
MovieHeader header = new MovieHeader();
header.setFrameRate(1.0f);
header.setFrameSize(new Bounds(-4000, -4000, 4000, 4000));
movie.add(header);
Generally porting was pretty painless. The biggest annoyance was having to changing type declarations for arrays from: ArrayList actions = new ArrayList(); to: List<Action> actions = new ArrayList<Action>();
There was one gotcha that took a little time to figure out (though not long). I ported Translate SWF to use classes in the new version of Transform rather rely on private copies intended to make the library independent of Transform. Now that actions are immutable:List<Object>values = push.getValues(); returned a copy of the array of values rather than a reference, so:List<Object>values = push.getValues(); has no effect. However once I had figured out / remembered what the problem was the change was trivial:
values.add(literal);List<Object>values = push.getValues();
values.add(literal);
actions.set(index, new Push(values));
Not all the change required to port an existing codebase are listed. The best guide would be to perform a diff between the new Cookbook examples when they are released, with the current version for Transform 2.3. That should give a good overview of what needs changing, at least for relatively simple applications.

February 18th, 2011 at 6:35 pm
I’m really grateful for the updated Transform library & Flash 10 capabilities but not so grateful for the porting! just kidding but really.
April 11th, 2011 at 9:11 pm
great post. Ne’er knew this, regards for letting me know.
July 12th, 2011 at 6:34 pm
I loved as a lot as you’ll acquire carried out ideal right here. The sketch is tasteful, your authored materials trendy. nonetheless, you command get purchased an shakiness over that you just want be delivering the following. unwell unquestionably arrive further formerly again as exactly exactly the same almost pretty typically inside case you shield this hike.
October 24th, 2011 at 4:31 pm
56. Hey very cool blog!! Man .. Excellent .. Amazing .. I’ll bookmark your site and take the feeds also…I’m happy to find a lot of useful info here in the post, we need develop more strategies in this regard, thanks for sharing. . . . . .
November 19th, 2011 at 4:44 pm
Weighty blog post. It’s useful information.
December 6th, 2011 at 1:28 pm
Has anyone here ever tried trading currencies and had any luck? I’m asking because I found this thing called a Forex robot for millionaires.. or something like that. I guess it is some kind of software that makes trades for you makes it so that you make money every time. Go check it out and let me know if you think this is the real deal: http://goo.gl/4qn42
December 16th, 2011 at 5:06 am
I truly appreciate this post. I’ve been looking all over for this! Thank goodness I found it on Bing. You have made my day! Thank you again
December 26th, 2011 at 4:46 pm
Pretty impressive post. I just stumbled upon your site and wanted to say that I have really enjoyed reading your opinions. Any way Ill be subscribing to your feed and I hope you post again soon.
December 29th, 2011 at 3:21 am
Il se révéler mauvais de fournir un prix avéré du moment que le coût appartient
January 5th, 2012 at 12:05 am
There are some interesting closing dates in this article but I don’t know if I see all of them middle to heart. There’s some validity but I will take maintain opinion until I look into it further. Good article , thanks and we wish extra! Added to FeedBurner as nicely
January 22nd, 2012 at 10:32 pm
ome really great things on this web site , I get pleasure from it.
February 2nd, 2012 at 2:21 am
Where by can i discover your rss feed?