Actionscript 3.0

The Flash TileList Component Sometimes Doesn’t Load All Items

Posted in Actionscript 3.0 on May 5th, 2010 by helloworlder – Be the first to comment

Why is this happening? Garbage collection is the culprit … again!

This StackOverflow page provides the solution.  The second answer - the one related to GC -  is the one that solved the problem for me, although you should check out the first one as well.

Intermittent Bugs Related To Garbage Collection

Posted in Actionscript 3.0 on March 15th, 2010 by helloworlder – Be the first to comment

I’ve been working with Actionscript 3.0 for some months now, and I’ve tripped over more than once when it came to garbage collection and memory management in general. Be very careful about letting local variables go out of scope, because the garbage collector may (or may not!) come to remove that variable before it finishes doing its job. This also results in one of the most frustration types of bugs - the intermittent bug.

For example, I used AS3’s TransitionManager class which allows you to create animations through code easily. I created an instance of the TransitionManager within an onclick handler, and used it to do slide a MovieClip onto the screen. However, sometimes the animation would stop before reaching the end. It might have stopped halfway, a quarter of way … every time it was different, but most of the time the slide in would complete. The problem was that the instance of TransitionManager was going out of scope as it was created in a method (in this case an onclick handler to be exact). Much of the time the garbage collector did not destroy the instance of the TransitionManager before it finished doing its animation, but sometimes it did, thus causing the animation to stop.

What I did was to make the instance of TransitionManager into a class variable. There might be other ways to do this though … Anyway the next time you see an intermittent bug in your program, it can be due to any reason - but remember this :-)

The Ongoing Role Of Flash On The Internet

Posted in Actionscript 3.0 on March 1st, 2010 by helloworlder – Be the first to comment

Flash already has an important role on the Internet when it comes to general interactive applications,  games and video.

Then there’s HTML5, which is supposedly going to replace many instances where Flash would otherwise be used. YouTube has been experimenting with using HTML5 instead of Flash. However, there is not yet any reason to believe that HTML5 and AJAX technologies will become a significant threat to Flash. The fact that HTML5 is an open standard doesn’t automatically put a halo on its head and a path to RIA domination, even though that may happen in the future.

Then there’s the ongoing Flash accessibility issue. Sure, Adobe has its fair share of problems and yes they still have, but they are concerned about accessibility and have been making improvements over time. For example, can screen readers read SWFs? Yes, they can. In fact, to provide accessibility developers can even provided built in readers and voice overs recorded by real people. Can users tab through components? Yes. The problem is becoming less of an issue of Flash itself than an issue of inaccessible design by developers. Remember, you can write inaccessible AJAX too.

The more relevant question regarding accessibility is now becoming  “Can Adobe provide developers with easier ways to implement accessibility?” instead of “Is Flash accessible?” Flash today isn’t the same as Flash 10 years ago, and I’ll bet you Flash in 10 years won’t be the same as Flash today.

Finally, while the Flash Platform is not open source, the SWF file format specification is open and free of charge to anyone. Yes, that includes you Apple!

I might be wrong, but I think Flash is not only here to stay, but we’ll see more diverse applications of it in the future. But I’m not betting on this one :-) The thing is, don’t dismiss the technology.

http://www.adobe.com/accessibility/

Why Do Package Names Start With com. In Actionscript 3?

Posted in Actionscript 3.0 on February 16th, 2010 by helloworlder – 1 Comment

Question:

Why do package names start with com. in Actionscript 3?

By the way, I’m guessing you already know that package names map to folder names. E.g. an as3 source file in the package com.example must be under the folder example, which in turn must be under the folder com..

Answer:

Package names do not have to begin with com. However, it is the convention to do so. E.g. com.thebestcompany.thebestproduct

What is the significance of com? Well, the package name is simply a domain name reversed. E.g com.helloworlder.utils

The domain name technically does not have to exist but you should own it. Obviously never use someone else’s domain name!! That’s just rude. It is standard practice to use a domain name because it helps to guarantee that your package names don’t collide with the names of someone else’s package on the other side of the world.

If I release some AS3 code that creates popup windows, I may place the code in a package called com.helloworlder.utils.popupwindow and not simply popupwindow

Likewise, if I download some third party code to use in my own project I’d expect their code to be packaged properly. E.g. com.goodbyeworld.utils.modalwindow. Then, I can just place their goodbyeworld folder under by own com folder.

Just as importantly, putting your as3 files into packages helps you think about how to organize the files. Often people place all files (their own and 3rd party code) under one folder! The advice is - don’t.


Unit Testing AS3 Code on the Flash CS4 Platform

Posted in Actionscript 3.0 on February 15th, 2010 by helloworlder – Be the first to comment

I’m developing a project on the Flash CS4 platform and finally started unit testing my AS3 code.  Not doing unit tests seems lazy and negligent. The only reliable unit testing framework I’ve found so far is asunit, which is open source. The Flash CS4 platform has been traditionally targeted at designers and not programmers so unit testing was somewhat neglected in the past.

Installation is very simple. Just unzip the archive and place the as3 folder anywhere on your system. Then in Flash CS4 go to Edit->Preferences and click on the button “Actionscript 3.0 Settings” at the bottom of the popup.  You need to add both of the following paths under “Source path”:

as3/src/

as3/test/

IMPORTANT: Don’t just add as3/ otherwise the framework files won’t be found.

That’s all for the installation. For usage, the asunit website has enough information to get you started.

Flash 0.05 Twip “Issue”

Posted in Actionscript 3.0 on September 13th, 2009 by helloworlder – Be the first to comment

If you ever try to add any number smaller than 0.05 to the x or y properties of any graphic, then you’ll will notice nothing will happen. It will not add anything smaller than 0.05.

Actually, this issue is due to the way Flash deals with pixels. In the wonderful world of typography, 1/20 of a pixel is called a twip, and 1/20 in decimals is not surprisingly 0.05. Graphics in Flash are positioned using twips, so Flash just ignores you if you try to move an object less than a twip.

Well, the solution is simple:

Instead of something like:

graphic.y += velocity.y; // velocity.y may be smaller than 0.05

you do something like:

yPositionTemp += velocity.y;
graphic.y = yPositionTemp;

Easy AdSense by Unreal