Reputation: 239
I am trying to call a function which is set inside a class..
How can I call that?
Here is my source, and I would like to call 'processLogin' from outside this class. Link to source: http://pastebin.com/aFygyXKZ
Upvotes: 0
Views: 1131
Reputation: 337
If you know you are only going to have one instance of the class main in your application, what you can do is:
main.getInstance().processLogin
or Just add a public static variable to your main class containing the instance of your main class. In this instance your code would look something like:
package actions {
import flash.display.MovieClip;
import flash.events.*;
import flash.net.*;
import flash.text.*;
public static var instance:main;
public function main(){
instance = this;
}
//The rest of your main class code...
}
That way, you can access your processLogin function using main.instance.processLogin()
.
However, if your application is set to possibly have more than one instance of your main class, then the best approach would be to instantiate main and use that instance, as f-a suggested.
Upvotes: 0
Reputation: 6359
You can create a new instance of your class main.
Try
var m:main = new main();
m.processLogin();
Also, AS3 best practices state that classes should begin with an Uppercase letter.
You also should extend Sprite instead of MovieClip for DisplayObject classes that do not need timeline functionality.
Upvotes: 2