AS3: Recursive Functions vs Loop Functions

A recursive function is a function that calls itself. The following code shows a simple example of recursion.

function trouble(){
trouble();
}

A recursive function like above calls itself unconditionally, cause infinite recursion. To prevent this from happening, practical recursion functions call themselves only while a given condition is met.
Continue reading

AS 3: Functions as Values

A function can be assigned to a variable, passed to a function, or returned from a function, just like any other values.

For example, the following code defines a function, a() and then assigns it to the variable b. Notice that the parentheses operator, (), is omitted; if it were included, the code would simply assign a()’s return value to b.

function a(){

}
var b=a;

Once a function has been assigned to a variable, it can be invoked through that variable using the standard parentheses operator, (). For example, the following code invokes the function a() through the variable b:

b();

Flash: the function of mergeAlpha in copyPixels

the sytx of copyPixels is like this:
copyPixels(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, [alphaBitmap:BitmapData], [alphaPoint:Point], [mergeAlpha:Boolean]) : Void

Just assume, we have a destination BMP called desBMP, a sourceBitmap, and a alphaBitmap to provide secondary alpha setting.

desBMP.copyPixels(sourceBitmap,sourceRect,destpoint,alphaBitmap,alphaPoint,mergeAlpha);

1. Things need to be clarified first


For desBMP, its transparency attribute is only defined when this BMP is created. it won’t be changed when the copy pixel happens.

2. How mergeAlpha works?


I search tons of help documents. It just said like
“mergeAlpha:Boolean (default = false) — To use the alpha channel, set the value to true. To copy pixels with no alpha channel, set the value to false. ”
There is no exmaple showing how this works and the effect of it.

After hundreds of tests, I got the following conclusions:

Continue reading

18 flash loading animations

Loading…. a most frequently used part in flash movie. To avoid your user see a blank screen and don’t know what happens, you provide them with loading animation indicating the progress and how long your user will be able to see the movie.

Of course, flash authorizing tool provide its progress bar component which has been universally used. However, if you want your movie looks different from the other, you might need to offer your user a unique loading animation. I have seen a lots of creative design for those. But, the more complicated loading animation, the larger swf file, which might cost user waiting sometime until they can see the loading part. That will be worse when our user has slow internet experience.

Continue reading