Saturday, April 30, 2005

While coding JSFL in the last few days, I found out from iterating through the library items that the items don't come in the order you see in the folder. They come in alphabetical order of the item name (sans the folder path).

Also, certain operations change the properties of an object. For example, by calling timeline.addNewLayer, you also change the property of the timeline.currentLayer to point to the newly inserted layer. The JSFI API documentation does a very poor job of explaining the side-effects for each function in the JSFL API. For example, it doesn't tell you when you should use setSelectedLayers, and how this call is related to currentLayer.

Whipped up a JSFL tool today that will take assets in one of your folder, and create layers on the timeline that matches the structure of the folder and insert the assets on those layers.

These days when people call event handlers for their movieclips or buttons, they either do it at the clip level, or they do it in the root timeline, by prefixing their handlers with the instance name. The advantage with doing it the former way is that you are a all-in-one button that can be easily reused when you copy and paste the asset into another Flash document. The downside is you have to hunt around for your function if your mc clip is deeply embedded. The pros and cons of the latter way is pretty much just the opposite.

A nice idea would be to create an extension to allow the coder to use the former way (making all entities well-encapsulated) but allow them to be able to find their code easily by simply selecting a list of instance names, they can navigate to the handler code for that that instance.

Thursday, April 28, 2005

Nice coding questions:

How to reverse a link list (constraint: do not allocate any memory)?
How to remove every n node in the link list (modulo N) in a circular fashion? (What data structure is needed?)
How do you implement a memory manager (to provide service for malloc and free)?
How do you test for palindrome?
How do you check the longest length of a palindrome in a given string?

Given a list of path names, write an algorithm to reconstruct it using File APIs of your OS for a particular file types in those paths.

e.g.
name: Color Pics/Red/002redapples3.jpg
name: Color Pics/Red/002redwagonplane2.jpg
name: Audio/Word/ALIEN.mp3
name: Audio/Spelled/A-L-I-E-N.mp3
name: Audio/Word/APPLE.mp3
name: Audio/Spelled/A-P-P-L-E.mp3
name: Audio/Question/AWhatColorPants.mp3
name: Color Pics/Black/city-night.jpg
name: Conclusion01.mp3
name: Conclusion02.mp3

Only pick out the path with Audio and with mp3 files in it and reconstruct it.

Monday, April 25, 2005

Project ideas: explore Flash SWF format and write tools that make sure of it.

Whipped up a JSFL to print out all your frame labels in a label:


var layers = fl.getDocumentDOM().getTimeline().layers;

var hasSeenFrames = new Array();
var frameLabelArray = new Array();

for (var i = 0; i < layers.length; i++)
{
var frames = layers[i].frames;

for (j = 0; j < frames.length; j++)
{
if (frames[j].labelType == 'name')
{
if (hasSeenFrames[frames[j].name] == undefined)
{
hasSeenFrames[frames[j].name] = 1;
frameLabelArray.push(frames[j].name);
}
}
}
}

for (var i = 0; i < frameLabelArray.length; ++i)
{
fl.trace(frameLabelArray[i]);
}

Common AS 1.0 coding mistakes

Using function classname.prototype.methodname() instead of classname.prototype.methodname() = function()

Forgetting to use this when calling an instance method from within the class itself.

Forgetting to convert _xmouse and _ymouse to global coordinate space when doing pixel level hit test. e.g. mc.hitTest(_xmouse, _ymouse, true); // not ok - x and y must be converted to global coordinate space first

Forgetting to use abs when you intend to test for magnitude less than a range
(by forgetting this, any large negative value will pass the test because they are always less than you positive limit)

e.g.

if ((x1 - x2) < 0.005)


Forgetting to introduce epsilon when you perform a floating point comparison

if (fp1 == fp2) // dangerous

instead do

if (abs(fp1 - fp2) < 0.001)


Common JSFL coding mistakes

Forgetting to use fl when you intend to trace (e.g. fl.trace()).

Sunday, April 24, 2005

Read about some interesting postings on Bezier curve as used in Flash drawing API today.
http://www.timotheegroleau.com/Flash/articles/cubic_bezier_in_flash.htm
http://www.actionscript.org/tutorials/advanced/Understanding_curves_and_control_point_placement/index.shtml

To sum it up basically Flash uses a quadratic Bezier curve, versus the more traditional cubic Bezier curve used in commercial vector graphic software. With quadratic curve (to refresh your memory of high school math, quadratic equation is an algebraic equation with the power term raised to power of 2, as in a*x^2 + b*x + c). So visually it means in Flash drawing API, you have two anchor points and one control point, giving you a quad curve. In order words, you can never get a closed circle or loop using just one curve.

Saturday, April 23, 2005

Wrote my first little JSFL today to automate setting the linkage name in the library for the symbols I created:


var itemArray = fl.getDocumentDOM().library.items;

for (var i = 0; i < itemArray.length; i++)
{
itemArray[i].linkageExportForAS = true;
itemArray[i].linkageIdentifier = itemArray[i].name;
}

A lot of books explain the difference between vector graphic and bitmap graphic (such as file size, level of control, scalability, etc.) It would be helpful to see how a vector graphic program is implemented as well. Should whip one up in C# ...