flash as3 Error: Error #2037 错误提示解决办法

Error: Error #2037: 函数调用序列不正确,或前面的调用不成功。

 代码如下 复制代码
at flash.media::Sound/_load()
at flash.media::Sound/load()
at org.mousebomb.media.musicPlayerV4::Mp3Container/loadMp3()
at org.mousebomb.media.musicPlayerV4::Mp3Container/nextMp3()
at org.mousebomb.media.musicPlayerV4::MusicPlayer/aC()

经过调查,这个错误的原因是:Sound对象只允许被load一个声音流,即使close()了也不能加载另一个声音.
一旦对某个 Sound 对象调用了 load(),就不能再将另一个声音文件加载到该 Sound 对象中。 若要加载另一个声音文件,请创建新的 Sound 对象。

外国人的解决办法

Sound files load asynchronously in Flash. Listen for the Event.COMPLETE event and in that event handler, add code to check if both are loaded and then play.

an example:

//

 代码如下 复制代码

Before you load,
myMusic2.addEventListener(Event.COMPLETE, musicLoaded);

//Event listener
private function musicLoaded(e:Event):void {
      //play logic here
      channel = myMusic.play(songPosition);
      channel2 = myMusic2.play(channel.position);
}

 

Example: do this:

 代码如下 复制代码

s = new Sound(req);

///do a bunch of stuff, and at some time later try to load a new mp3 in
s.load(req);

You will get

Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful.

For each new mp3 you need to create a new Sound object. Note that SoundChannel is like a playhead, more than one of them can be accessing the Sound data, so you can create chorus/echo effects by triggering play() multiple times at different time/offsets. Here's a sound player that cycles through 2 mp3s with no errors, and caches the results.

 代码如下 复制代码

import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.*;
import com.troyworks.core.persistance.CacheEvent;

var mp3s:Array = ["test.mp3","BT - Satellite.mp3"];

var cache:Object = new Object();

playNext_mc.addEventListener(MouseEvent.CLICK, playSound);

var s:Sound;
var _channel:SoundChannel;

function getNextAudioURL():String {
var curURL:String = mp3s.shift();
mp3s.push(curURL);
return curURL;
}
function playSound(evt:Event = null) {
var audioSwfURL:String = getNextAudioURL();
trace("***************************************************************");
trace("playSound " +audioSwfURL);
//trace(" attempting to restore " + audioSwfURL + " into AUDIO");
try {
if (_channel != null) {
//_channel.stop(); //UNCOMMENT ME TO STOP THE PREVIOUS PLAYING TRACK
//s.load(); //won't work with progressive
//s.close(); //won't work with progressive
}
if (audioSwfURL != null && cache[audioSwfURL] == null) {

//////////// normal audio loading ////////////
var req:URLRequest = new URLRequest(audioSwfURL);
s = new Sound();
//speaker_mc.display_txt.text =".";
s.addEventListener(Event.COMPLETE, onSoundLoaded);
s.addEventListener(IOErrorEvent.IO_ERROR, onSoundFailedToLoad);
s.load(req);
}else{

//////////// use cached audio ////////////////
trace("hitting cache");
var cevt:CacheEvent = new CacheEvent(Event.COMPLETE);
cevt.target = cache[audioSwfURL];
onSoundLoaded(cevt);
}
} catch (err:IOError) {
trace(err.toString());
} catch (err:Error) {
trace(err.toString());
}
}

function onSoundFailedToLoad(Event:IOErrorEvent):void {
trace("onSoundLoaded **FAILED**");
//speaker_mc.display_txt.text = "!";
}
function onSoundLoaded(event:Event ):void {
//speaker_mc.display_txt.text = "";

var localSound:Sound = event.target as Sound;

////////////// parse the key mp3 name /////////////////

//NOTE: a cleaner approach way would to be a Proxy that passes arguments along with the event, created during //the listener

 代码如下 复制代码

var url:String = localSound.url;
var a:Number = url.lastIndexOf("/");
var b:Number = url.lastIndexOf("\");
var c:Number = Math.max(a,b);
var url2:String = url.substr(c+1, url.length);
trace("onSoundLoaded" + url2);

//////////// cache it ////////////////////////
cache[url2] = localSound;
_channel = localSound.play();
localSound.addEventListener(Event.SOUND_COMPLETE, onPlayComplete);

}
function onPlayComplete(evt:Event):void {
//if has more sounds play them else, move to next slide
//content_mc.play();
}
playSound();

Caching Sounds...or anything for that matter

Once you've loaded a Sound(Bitmap etc) it's in memory so if your reusing it (e.g. Sound FX) there's no need to reload it. Here you can use a  cache, using the name of the sound as a key, and a CustomEvent to mimic the loaded event, as the default Event target is readonly, so you can't mimic the call coming from the cache. The solution is to override it, and call the listeners directly if you can't redispatch using the original sound.  The advantage is the loading event, don't know the difference between the real or loaded. The cache might also be used for offline/online type activities. But of course be aware you're memory useage for caching like this can get large quickly.

 代码如下 复制代码

package com.troyworks.core.persistance {
import flash.events.*;
public class CacheEvent extends Event {

private var _overriddenTarget:Object;

public function CacheEvent(type:String,bubbles:Boolean=false, cancelable:Boolean=false) {
super(type, bubbles, cancelable);
}
override public function get target():Object{
return _overriddenTarget;
}
public function set target(target:Object):void{
_overriddenTarget = target;
}

}

}

时间: 2024-09-20 00:13:53

flash as3 Error: Error #2037 错误提示解决办法的相关文章

Adobe dw cs5 出现RecordsetFind错误提示解决办法

adobe dw cs5 出现recordsetfind错误提示解决办法 经过分析出现这种问题是在你关机或cs5不稳定引起的,下面我们来看处理办法, 一,把你的dw给关了, 二,打开c:documents and settings你的用户名application dataadobe目录下,找到与你软件相同的目录,直接delete删除. 三,重启dw 就可以了, 注:如果有的用户会找不到你自己的用户名,解决方法 工具菜单->文件夹选项->点击查看选项卡-->勾上显示所有文件就可以了.

MySQL ERROR 1045 (28000) 错误的解决办法_Mysql

错误现象: ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)  ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: YES)  windows下,以上两个错误的解决方法,本人亲测有效,现分享解决方案如下:  1.找到配置文件my.ini  ,然后将其打开,可以选择用记事本打开.

MySql出现#1036错误提示解决办法

我本以为这已经是顺利迁移完成了,但后来操作的时候,发现只能读取数据库的内容,不能更改写入任何信息,提示#1036 – Table '* ' is read only (*号为任意表),也就是说表只有只读属性. 通过SSH,给数据库文件777权限,dedeadmin是我的数据库文件夹 chmod -R 0777 /usr/local/mysql/var/dedeadmin/ 给数据库目录的所属用户和组改为MySQL chown -R mysql:mysql dedeadmin 但是这样还不能更改数

mysql出现Error Code:1418 错误的解决办法

错误信息如下: 以下是引用片段:Error Code : 1418 This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable) (0 ms taken) 解决方法如下

PHP Parse Error: syntax error, unexpected $end 错误的解决办法_php技巧

这几天写php程序,感觉很多地方不如asp,asp.Net,jsp顺手,比如session使用先得session_start();,文件跳转header用的也不方便.... 也许是不熟悉的php的一些特性吧,不过写多了,也就慢慢适应将就了..... 这里就整理一个代码编写调试问题,错误如下: Parse error: syntax error, unexpected $end in D:\xampp\htdocs\guestBook\guestBook.php on line 330 看看程序

mysql的Error Code:1418 错误的解决办法

Error Code : 1418 This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable) (0 ms taken) 解决方法如下: 1. mysql> SET

Oracle数据库启动ORA-08103错误提示解决办法

数据库在open过程报ORA-08103错误导致数据库无法正确启动  代码如下 复制代码 Fri Jul 18 22:02:51 2014 SMON: enabling tx recovery Fri Jul 18 22:02:51 2014 Errors in file d:\oracle\product\10.2.0\admin\kemu3\udump\kemu3_ora_29788.trc: ORA-00604: ?? SQL ?? 1 ???? ORA-08103: ??????   F

jQuery Uploadify 上传插件出现Http Error 302 错误的解决办法_jquery

前段时间介绍过jquery uploadify上传插件的使用方法,我在使用中遇到过Http Error 302错误问题,应该会有很多人在使用中遇到过,在此记录下来: 首先http 302是请求被重定向的意思,这就很容易理解了,如果你的uploadify处理上传脚本有session验证,就会出现此错误,因为flash在执行post请求的时候没有包含cookie信息,而服务器的session会根据客户端的cookie来得到SESSIONID.没有提交cookie自然就不能获取到session,然后u

CentOS6 X11提示Fatal server error:no screens found的解决办法

安装完CentOS-6.6-x86_64-minimal以后,再给它装个桌面,于是运行了yum groupinstall "Desktop",按理说,应该是桌面环境应该可以正常运行了.但当运行start命令时,却遇到了如下错误: Fatal server error: .......  no screens found (EE)  Please consult the CentOS support   at http://wiki.centos.org/Documentation  f