tags:

views:

48

answers:

2
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"
 />
+1  A: 

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;
Jeff L
A: 

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.

Christopher W. Allen-Poole