I have some code for Flash to simulate moving clouds. It worked under AS1 and now I have updated the FLA file to AS3 and minimum Flash version 10. What is wrong with this code? Can you help see what is wrong with this function?
function createLiquidFlow(target)
{
target.counter = 1;
target.pt = new flash.geom.Point(0, 0);
target.mpoint = new flash.geom.Point(0, 0);
// target.myBitmap = new flash.display.BitmapData(target._width, target._height, false, 0);
target.myBitmap = new flash.display.BitmapData(target.width, target.height, false, 0 );
target.myDispl = new flash.filters.DisplacementMapFilter(target.myBitmap, target.mpoint, 10, 2, 10, 15, "clamp");
target.myList = new Array();
target.myList.push(target.myDispl);
target.filters = target.myList;
target.addEventListener(Event.ENTER_FRAME,
function ()
{
trace("target.name = "+target.name);
trace("target.myBitmap = "+target.myBitmap);
trace("target.myBitmap.width = "+target.myBitmap.width);
trace("target.myBitmap.height = "+target.myBitmap.height);
trace("target.counter = "+target.counter);
var filterList = target.filters;
var offset = new Array();
offset[1] = new Object();
offset[1].x = target.counter;
offset[1].y = target.counter / 2;
target.myBitmap.perlinNoise(45, 6, 3, 50, true, false, 7, true, offset);
filterList.mapBitmap = target.myBitmap;
target.filters = filterList;
++target.counter;
});
}
createLiquidFlow( movieClipLiquid )
I can trace the event listener, but the bitmap and Perlin function appears not to work. There is nothing visually happening in the output SWF. TIA
target.name = liquid74_mc
target.myBitmap = [object BitmapData]
target.myBitmap.width = 950
target.myBitmap.height = 76
target.counter = 1
myFilterList = [object DisplacementMapFilter]
BEFORE myFilterList.mapBitmap = undefined
AFTER myFilterList.mapBitmap = [object BitmapData]
BEFORE target.filters = [object DisplacementMapFilter]
AFTER target.filters = [object DisplacementMapFilter]
target.name = liquid74_mc
target.myBitmap = [object BitmapData]
target.myBitmap.width = 950
target.myBitmap.height = 76
target.counter = 2
myFilterList = [object DisplacementMapFilter]
BEFORE myFilterList.mapBitmap = undefined
AFTER myFilterList.mapBitmap = [object BitmapData]
BEFORE target.filters = [object DisplacementMapFilter]
AFTER target.filters = [object DisplacementMapFilter]
The answer is ActionScript 3 is more stricter on types rather than ActionScript 1. The Bitmap.perlinNoise requires an offset that is an Array of Point objects. In Java this would be same as
and is the same as
In the ActionScript I changed the parameterised type from Object to flash.geom.Point. Also the first element of the Array was never defined. In order to liquidate the animation I kept the second offset and redefined it as a flash.geom.Point also. The working code, thus follows: