通过静态类的引用来调用可能未定义的方法测试 。
这是我的班级
package com.singleton.sample{
public class SampleSingleton{
public static function test( ):void{
trace( hello world )
}
}
}
这是我的Mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()">
<mx:Script>
<![CDATA[
import com.singleton.sample.SampleSingleton;
public function init():void{
SampleSingleton.test() // error on this line
}
]]>
</mx:Script>
</mx:Application>
请忽略在命名中单人字的引用,
[编辑]
import com.singleton.sample.SampleSingleton;
public function init():void{
SampleSingleton.test(); // this gives me the error
com.singleton.sample.SampleSingleton.test(); // this works
}