AS2项目中视频播放完成后附属影片剪辑无法移除的问题求助
AS2视频播放完成后无法移除边框影片剪辑的解决方案
问题根源
你在创建边框剪辑时,使用attachMovie指定的实例名是_borderLeft和_borderRight(带下划线),但后续尝试删除时多次误用了不带下划线的borderLeft/borderRight,导致找不到目标剪辑;另外部分代码中对实例引用的访问逻辑存在偏差。
修复后的destroyVideoPlayer函数
直接使用类中保存的_borderLeft和_borderRight引用进行清理,同时完善资源释放逻辑:
function destroyVideoPlayer() { // 关闭NetStream,释放视频流资源 if (this.ns != null) { this.ns.close(); this.ns = null; } // 清理Video实例 if (this.videoInstance != null) { this.videoInstance.clear(); this.videoInstance = null; } // 移除左侧边框剪辑 if (this._borderLeft != null && this._borderLeft._parent == _root) { this._borderLeft.removeMovieClip(); this._borderLeft = null; } // 移除右侧边框剪辑 if (this._borderRight != null && this._borderRight._parent == _root) { this._borderRight.removeMovieClip(); this._borderRight = null; } // 移除视频容器 if (_root.videoWrapper != null) { _root.videoWrapper.removeMovieClip(); this.videoWrapper = null; } }
关键注意事项
- AS2中
removeMovieClip()仅对通过attachMovie、duplicateMovieClip或动态创建的影片剪辑有效,需确保目标剪辑是通过上述方式生成的。 - 清理后将引用设为
null,避免内存泄漏,同时防止后续误操作。 - 你在
ns.onStatus回调中使用StoryMode.getInstance()调用销毁方法的逻辑是正确的,确保了作用域无误。
验证方法
在destroyVideoPlayer函数末尾添加调试输出,确认实例已被移除:
trace("borderLeft:", _root._borderLeft, "borderRight:", _root._borderRight, "videoWrapper:", _root.videoWrapper);
内容的提问来源于stack exchange,提问作者user28541024
相关产品推荐
相关产品推荐

