Posts Tagged ‘actionscript’

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