Actionscript 3 Can';t扩展声音对象原型

Actionscript 3 Can';t扩展声音对象原型,actionscript-3,flash,object,audio,prototype,Actionscript 3,Flash,Object,Audio,Prototype,我是编程新手。我需要向声音对象添加新属性,但无法使其工作。这就是我正在做的: S31 = new Sound(); S31.load(new URLRequest("mp3/S31.mp3")); Sound.prototype.correctas = 0; trace(S31.correctas); 我收到以下错误消息: “1119:通过引用静态类型flash访问可能未定义的属性correctas。媒体:声音” 我不知道该怎么办 谢谢你抽出时间 原型类实际上没有在as3中使用(如果我在这里错

我是编程新手。我需要向声音对象添加新属性,但无法使其工作。这就是我正在做的:

S31 = new Sound();
S31.load(new URLRequest("mp3/S31.mp3"));
Sound.prototype.correctas = 0;
trace(S31.correctas);
我收到以下错误消息:

“1119:通过引用静态类型flash访问可能未定义的属性correctas。媒体:声音”

我不知道该怎么办


谢谢你抽出时间

原型类实际上没有在as3中使用(如果我在这里错了,请有人纠正我,我知道它包括但我不确定为什么要使用它。)

您可以创建允许您在运行时向其添加属性的类,但在本例中,我将坚持使用OOP

您要做的是创建一个扩展声音的类,并保存您想要包含的任何扩展功能。这个新类将包含基本声音类的所有功能

试着让它扩展声音

package src {
import flash.media.Sound;
import flash.media.SoundLoaderContext;
import flash.net.URLRequest;

    public class MySound extends Sound{

    public var correctas:Number; //assuming you are using a Number here          

    //sound takes two params in its constructor 
    public function MySound(stream:URLRequest=null, context:SoundLoaderContext=null){
    //super passes these params to the super class
        super(stream, context);
     }
}
现在要使用它,您需要创建一个新的MySound对象,而不是声音

 var s31:MySound = new MySound();
 s31.load(new URLRequest("mp3/S31.mp3"));
 s31.correctas = 0;
 trace(s31.correctas) //will be 0