Reputation: 23634
package asas
{
public class main extends EventDispatcher
{
private static var instance:main =new main;
// This method returns the instance of the class.
public static function get instance() : main {
if(_instance == null){
_instance = new main();
}
return _instance;
}
public function doCheck():void {
}
I have this class and a MXML file... how will i call the function doCheck in button. When i call like this, it throws me an error.
<mx:Button
styleName="LoginButton"
id="loginButton"
click="main.instance.doCheck();"
x="160"
y="261"
/>
Upvotes: 0
Views: 552
Reputation: 123
This line of the code doesn't make sense, because in your code you use undeclared variable.
private static var instance:main =new main;
use should change it to:
private static var _instance:main;
Upvotes: 0
Reputation: 82078
Jeff L is right on implementation. The _instance property should always be uninitialized or set to null. That said, that is not the issue here.
I have had poor results when trying to get MXML to read methods off of properties of other objects in that notation. I recommend replacing this:
<mx:Button
styleName="LoginButton"
id="loginButton"
click="main.instance.doCheck();"
x="160"
y="261"
/>
with one that uses brackets:
<mx:Button
styleName="LoginButton"
id="loginButton"
click="{ main.instance.doCheck(); }"
x="160"
y="261"
/>
That generally will give me more reliable behavior, and I think that will help here too.
Upvotes: 0
Reputation: 6198
Your private instance variable is named instance
, but your trying to assign to a variable called _instance
in the getter.
Change this:
private static var instance:main =new main;
to this:
private static var _instance:main;
Upvotes: 1