0

我有一些 Flash 代码来模拟移动的云。它在 AS1 下工作,现在我已将 FLA 文件更新为 AS3 和最低 Flash 版本 10。这段代码有什么问题?你能帮忙看看这个功能有什么问题吗?

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 )

我可以跟踪事件侦听器,但位图和 Perlin 函数似乎不起作用。输出 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]
4

1 回答 1

0

答案是 ActionScript 3 在类型上比 ActionScript 1 更严格。 Bitmap.perlinNoise 需要一个 Point 对象数组的偏移量。在 Java 中,这将与

List<Point> points = new ArrayList<Point>()

和一样

List<Object> points = new ArrayList<Object>()

在 ActionScript 中,我将参数化类型从 Object 更改为 flash.geom.Point。数组的第一个元素也从未定义过。为了清理动画,我保留了第二个偏移量并将其重新定义为 flash.geom.Point。工作代码如下:

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 (e:Event)
            {
                var myFilterList = target.filters;
                var offset = new Array();
                offset[0] = new Point(0, 0);
                offset[1] = new Point(target.counter, target.counter / 2);
                target.myBitmap.perlinNoise(45, 6, 3, 50, true, false, 7, true, offset);
                myFilterList.mapBitmap = target.myBitmap;
                target.filters = myFilterList;
                ++target.counter;
            });
    // Arguments to PerlinNoise function
    // baseX:Number — Frequency to use in the x direction. For example, to generate a noise that is sized for a 64 x 128 image, pass 64 for the baseX value.
    // baseY:Number — Frequency to use in the y direction. For example, to generate a noise that is sized for a 64 x 128 image, pass 128 for the baseY value.
    // numOctaves:uint — Number of octaves or individual noise functions to combine to create this noise. Larger numbers of octaves create images with greater detail. Larger numbers of octaves also require more processing time.
    // randomSeed:int — The random seed number to use. If you keep all other parameters the same, you can generate different pseudo-random results by varying the random seed value. The Perlin noise function is a mapping function, not a true random-number generation function, so it creates the same results each time from the same random seed.
    // stitch:Boolean — A Boolean value. If the value is true, the method attempts to smooth the transition edges of the image to create seamless textures for tiling as a bitmap fill.
    //  fractalNoise:Boolean — A Boolean value. If the value is true, the method generates fractal noise; otherwise, it generates turbulence. An image with turbulence has visible discontinuities in the gradient that can make it better approximate sharper visual effects like flames and ocean waves.
    //  channelOptions:uint (default = 7) — A number that can be a combination of any of the four color channel values (BitmapDataChannel.RED, BitmapDataChannel.BLUE, BitmapDataChannel.GREEN, and BitmapDataChannel.ALPHA). You can use the logical OR operator (|) to combine channel values.
    //  grayScale:Boolean (default = false) — A Boolean value. If the value is true, a grayscale image is created by setting each of the red, green, and blue color channels to identical values. The alpha channel value is not affected if this value is set to true.
    //offsets:Array (default = null) — An array of points that correspond to x and y offsets for each octave. By manipulating the offset values you can smoothly scroll the layers of a perlinNoise image. Each point in the offset array affects a specific octave noise function.                             
}

createLiquidFlow( movieClipLiquid )
于 2011-12-29T12:21:47.817 回答