Actionscript 3 动作脚本3删除声音对象
在我的代码中,我定义了声音、声音频道和URL请求,如下所示:Actionscript 3 动作脚本3删除声音对象,actionscript-3,audio,Actionscript 3,Audio,在我的代码中,我定义了声音、声音频道和URL请求,如下所示: private var url:String = "MySound.mp3"; private var oSound:Sound; private var oSoundChannel:SoundChannel; ... var request:URLRequest = new URLRequest(url); this.oSound = new Sound(); this.oSound.load(request); this.oSo
private var url:String = "MySound.mp3";
private var oSound:Sound;
private var oSoundChannel:SoundChannel;
...
var request:URLRequest = new URLRequest(url);
this.oSound = new Sound();
this.oSound.load(request);
this.oSoundChannel.stop();
this.url = "deejay.mp3";
var request:URLRequest = new URLRequest(this.url);
this.oSound = new Sound();
this.oSound.load(request);
this.oSoundChannel = oSound.play();
用户可以选择新的声音并进行更改。这个过程(我的意思是改变声音)可以重复。
如下图所示:
private var url:String = "MySound.mp3";
private var oSound:Sound;
private var oSoundChannel:SoundChannel;
...
var request:URLRequest = new URLRequest(url);
this.oSound = new Sound();
this.oSound.load(request);
this.oSoundChannel.stop();
this.url = "deejay.mp3";
var request:URLRequest = new URLRequest(this.url);
this.oSound = new Sound();
this.oSound.load(request);
this.oSoundChannel = oSound.play();
我的问题(关于内存泄漏/丢失):
在加载新的声音文件之前,是否需要删除对象(例如声音、SoundChannel或URLRequest)?
如果是,如何删除该元素
// E.g. something like: oSound.parent.removeChild(oSound); // <-- It doesn't work properly!
//例如:oSound.parent.removeChild(oSound);//oSound=null如果您想再次使用if(oSound==null){oSound=new Sound()}
这个问题被误导了。你不能从任何东西上移除声音对象。像AS3中的每个对象一样,您将它们限定为GC。