我写了一个单独的类来跟踪一些变量在我的应用程序。
I wrote a singleton class to keep track of some variables across my application.
我得到一个语法错误,我想不通,我敢肯定,我失去了一些东西简单,但它是那些日子之一。任何人看到的东西错了我的code?
I am getting a syntax error that I can't figure out, I am sure that I am missing something simple but it's been one of those days. Anyone see something wrong with my code?
该错误是1061:通过静态类型类引用调用可能未定义的方法的setResult
The error is 1061: Call to a possibly undefined method setResult through a reference with static type Class.
我在我的单例类的功能
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页我的函数调用
My function call in my mxml page
if(chkBox1.selected == true)
{
utils.Calculation.setResult(2,1);
}
在此先感谢您的帮助!
Thanks in advance for any help!
假设你单是计算类,你缺少你的getInstance调用?
Assuming you singleton is the Calculation class, are you missing your getInstance call?
utils.Calculation.getInstance().setResult(2, 1);
一个很好的动作Singleton模式:
A good actionscript singleton pattern:
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()为例进行计算类:
getInstance() example for the Calculation class:
private static var calculation:Calculation;
public static function getInstance():Calculation{
if(calculation==null)
calculation = new Calculation(SingletonLock);
return calculation;
}