最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
flash as3 Error: Error #2037 错误提示解决办法
时间:2022-06-28 22:15:56 编辑:袖梨 来源:一聚教程网
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,
|
Example: do this:
代码如下 | 复制代码 |
s = new Sound(req); ///do a bunch of stuff, and at some time later try to load a new mp3 in |
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; var mp3s:Array = ["test.mp3","BT - Satellite.mp3"]; var cache:Object = new Object(); playNext_mc.addEventListener(MouseEvent.CLICK, playSound); var s:Sound; function getNextAudioURL():String { //////////// normal audio loading //////////// //////////// use cached audio //////////////// function onSoundFailedToLoad(Event:IOErrorEvent):void { 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; //////////// cache it //////////////////////// } |
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 { private var _overriddenTarget:Object; public function CacheEvent(type:String,bubbles:Boolean=false, cancelable:Boolean=false) { } } |
相关文章
- 银与绯啖魂怎么获取 银与绯啖魂获取方法介绍 07-08
- 2025年最火的虚拟币-2025年十大虚拟币种 07-08
- Pump.fun的陨落是对所有"快速行动、打破常规"项目的警示 07-08
- 我的魔法英雄伙伴选择什么法师好 我的魔法英雄伙伴法师选择推荐大全 07-08
- 侠客回忆录2为什么要组队 侠客回忆录2组队重要性一览 07-08
- 最新比特币持币地址数量介绍-2025年比特币持币地址有多少个 07-08