动作3 - 引发RangeError:错误#2004 - 我究竟做错了什么? [英] ActionScript 3 - RangeError: Error #2004 - What am I doing wrong?

查看:158
本文介绍了动作3 - 引发RangeError:错误#2004 - 我究竟做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code的加载声音,请将test.mp3',然后降低其音高,也减缓下来。声音可以正常播放在较低的间距,但在取样结束后,我得到这个错误:引发RangeError:错误#2004:其中一个参数是无效的。什么我做错了,我该如何解决这个问题?任何帮助将非常AP preciated。

  VAR sourceSound:声音=新的声音();
VAR outputSound:声音=新的声音();

VAR的URLRequest:的URLRequest =新的URLRequest(请将test.mp3');

sourceSound.load(的URLRequest);
sourceSound.addEventListener(引发Event.COMPLETE,soundLoaded);

功能soundLoaded(事件:事件):无效{

    outputSound.addEventListener(的SampleDataEvent.SAMPLE_DATA,processSound);
    outputSound.play();

}

功能processSound(事件:的SampleDataEvent):无效{

    VAR字节:的ByteArray =新的ByteArray();
    sourceSound.extract(字节,4096);
    VAR returnBytes:ByteArray的=新的ByteArray();
    bytes.position = 0;

    而(bytes.bytesAvailable大于0){

        returnBytes.writeFloat(bytes.readFloat());
        returnBytes.writeFloat(bytes.readFloat());
        bytes.position  -  = 4;
        returnBytes.writeFloat(bytes.readFloat());

    }

    event.data.writeBytes(returnBytes);

}
 

解决方案

我被解决,而不是要回一半以上的字节在每次迭代,将在所有的字节每隔一个循环它。所以processSound函数现在看起来是这样的:

 函数processSound(事件:的SampleDataEvent):无效{

    VAR字节:的ByteArray =新的ByteArray();
    sourceSound.extract(字节,4096);
    bytes.position = 0;

    VAR returnBytes:ByteArray的=新的ByteArray();

    VAR数:INT;

    而(bytes.bytesAvailable大于0){

        returnBytes.writeFloat(bytes.readFloat());
        returnBytes.writeFloat(bytes.readFloat());

        算上++;

        如果(计数%2 === 0){

            bytes.position- = 8;
            returnBytes.writeFloat(bytes.readFloat());
            returnBytes.writeFloat(bytes.readFloat());

        }

    }

    event.data.writeBytes(returnBytes);
}
 

I have the following code which loads a sound, 'test.mp3', and then lowers its pitch, also slowing it down. The sound plays correctly at the lower pitch but at the end of the sample, I get this error: 'RangeError: Error #2004: One of the parameters is invalid.'. What am I doing wrong and how can I fix this problem? Any help on this would be very much appreciated.

var sourceSound:Sound = new Sound();
var outputSound:Sound = new Sound();

var urlRequest:URLRequest=new URLRequest('test.mp3');

sourceSound.load(urlRequest);
sourceSound.addEventListener(Event.COMPLETE, soundLoaded);

function soundLoaded(event:Event):void {

    outputSound.addEventListener(SampleDataEvent.SAMPLE_DATA, processSound);
    outputSound.play();

}

function processSound(event:SampleDataEvent):void {

    var bytes:ByteArray = new ByteArray();
    sourceSound.extract(bytes, 4096);
    var returnBytes:ByteArray = new ByteArray();
    bytes.position=0;

    while (bytes.bytesAvailable > 0) {

        returnBytes.writeFloat(bytes.readFloat());
        returnBytes.writeFloat(bytes.readFloat());
        bytes.position -= 4;
        returnBytes.writeFloat(bytes.readFloat());

    }

    event.data.writeBytes(returnBytes);

}

解决方案

I solved it by, instead of going back over half the bytes on every iteration, going over all of the bytes every other iteration. So the processSound function now looks like this:

function processSound(event:SampleDataEvent):void {

    var bytes:ByteArray = new ByteArray();
    sourceSound.extract(bytes, 4096);
    bytes.position=0;

    var returnBytes:ByteArray = new ByteArray();

    var count:int;

    while (bytes.bytesAvailable > 0) {

        returnBytes.writeFloat(bytes.readFloat());
        returnBytes.writeFloat(bytes.readFloat());

        count++;

        if (count%2 === 0) {

            bytes.position-=8;
            returnBytes.writeFloat(bytes.readFloat());
            returnBytes.writeFloat(bytes.readFloat());

        }

    }

    event.data.writeBytes(returnBytes);
}

这篇关于动作3 - 引发RangeError:错误#2004 - 我究竟做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆