Apache flex 通过静态类型类的引用调用可能未定义的方法

Apache flex 通过静态类型类的引用调用可能未定义的方法,apache-flex,actionscript-3,Apache Flex,Actionscript 3,我编写了一个单例类来跟踪应用程序中的一些变量 我得到了一个语法错误,我不明白,我肯定我错过了一些简单的东西,但这是其中的一天。有人看到我的代码有问题吗 错误是1061:通过静态类型类的引用调用可能未定义的方法setResult 我在我的单人课上的作用 public function setResult(resultNumber:int, value:int): void { switch(resultNumber) { case 2

我编写了一个单例类来跟踪应用程序中的一些变量

我得到了一个语法错误,我不明白,我肯定我错过了一些简单的东西,但这是其中的一天。有人看到我的代码有问题吗

错误是1061:通过静态类型类的引用调用可能未定义的方法setResult

我在我的单人课上的作用

public function setResult(resultNumber:int, value:int): void
    {
        switch(resultNumber)
        {
            case 2: { this.result2 = value; break; }
            case 3: { this.result3 = value; break; }
            case 4: { this.result4 = value; break; }
            case 5: { this.result5 = value; break; }
            case 6: { this.result6 = value; break; }
            case 7: { this.result7 = value; break; }
            case 8: { this.result8 = value; break; }
            case 9: { this.result9 = value; break; }
            case 10: { this.result10 = value; break; }
            case 11: { this.result11 = value; break; }
            case 12: { this.result12 = value; break; }
            case 13: { this.result13 = value; break; }
            case 14: { this.result14 = value; break; }
        }
    }
我的mxml页面中的函数调用

            if(chkBox1.selected == true)
            {
                utils.Calculation.setResult(2,1);
            }
提前感谢您的帮助

试试这个:

public static function setResult(...) 
试试这个:

public static function setResult(...) 

假设singleton是计算类,是否缺少getInstance调用

utils.Calculation.getInstance().setResult(2, 1);
一个好的actionscript单例模式:

package com.stackOverflow
{
    public class MySingleton
    {
        public function MySingleton(lock:Class)
        {
            if(lock != SingletonLock)
                throw new Error("This class cannot be instantiated, it is a singleton!");
        }
        private static var mySingleton:MySingleton;

        public static function getInstance():MySingleton{
            if(mySingleton==null)
                mySingleton = new MySingleton(SingletonLock);
            return mySingleton;
        }
        public function setResult(resultNumber:int, value:int): void{
        //...
        }
    }
}
class SingletonLock{}
编辑:getInstance()计算类的示例:

private static var calculation:Calculation;
public static function getInstance():Calculation{
    if(calculation==null)
        calculation = new Calculation(SingletonLock);
    return calculation;
}

假设singleton是计算类,是否缺少getInstance调用

utils.Calculation.getInstance().setResult(2, 1);
一个好的actionscript单例模式:

package com.stackOverflow
{
    public class MySingleton
    {
        public function MySingleton(lock:Class)
        {
            if(lock != SingletonLock)
                throw new Error("This class cannot be instantiated, it is a singleton!");
        }
        private static var mySingleton:MySingleton;

        public static function getInstance():MySingleton{
            if(mySingleton==null)
                mySingleton = new MySingleton(SingletonLock);
            return mySingleton;
        }
        public function setResult(resultNumber:int, value:int): void{
        //...
        }
    }
}
class SingletonLock{}
编辑:getInstance()计算类的示例:

private static var calculation:Calculation;
public static function getInstance():Calculation{
    if(calculation==null)
        calculation = new Calculation(SingletonLock);
    return calculation;
}

如果我使用static,那么我就不能使用this。关键字要访问我的variablesOP,如果要将其设置为静态,则还需要删除函数中对
this
的引用。如果我使用静态,则无法使用this。关键字要访问my variablesOP,如果要使函数成为静态的,还需要删除函数中对该的引用。使用方法会导致错误1046:找不到类型或类型不是编译时常量:getInstance()函数声明行处的计算在计算中重命名MySingleton。这只是一个示例。公共静态函数getInstance():Calculation{if(Calculation==null)Calculation=new Calculation();return Calculation;}无论发生什么错误,我都缺少getInstance(),因此非常感谢您的帮助!使用您的方法会导致错误1046:找不到类型或类型不是编译时常量:计算中getInstance()函数声明行Rename MySingleton处的计算。这只是一个示例。公共静态函数getInstance():Calculation{if(Calculation==null)Calculation=new Calculation();return Calculation;}无论发生什么错误,我都缺少getInstance(),因此非常感谢您的帮助!