Reputation: 11
I have this code for a login tutorial that I followed.
package {
/*
always extend a class using movieclip instead of sprite when using flash.
*/
import flash.display.MovieClip;
import flash.events.*;
import flash.net.*;
import flash.text.*;
/*
create our class
*/
public class login extends MovieClip {
;
public function login ():void {
var login_form:login = new login();
addChild(login_form);
var username:TextField = new TextField();
addChild(username);
var password:TextField = new TextField();
addChild(password);
var login_button:MovieClip = new MovieClip();
addChild(login_button);
/*
buttonMode gives the submit button a rollover
*/
login_button.buttonMode = true;
/*
what this says is that when our button is pressed, the checkLogin function will run
*/
login_button.addEventListener(MouseEvent.MOUSE_DOWN, checkLogin);
/*
set the initial textfield values
*/
username.text = "";
password.text = "";
}
public function checkLogin (e:MouseEvent):void {
var username:TextField = new TextField();
addChild(username);
var password:TextField = new TextField();
addChild(password);
/*
check fields before sending request to php
*/
if (username.text == "" || password.text == "") {
/*
if username or password fields are empty set error messages
*/
if (username.text == "") {
username.text = "Enter your username";
}
if (password.text == "") {
password.text = "Enter your password";
}
} else {
/*
init function to process login
*/
processLogin();
}
}
public function processLogin ():void {
var username:TextField = new TextField();
addChild(username);
var password:TextField = new TextField();
addChild(password);
/*
variables that we send to the php file
*/
var phpVars:URLVariables = new URLVariables();
/*
we create a URLRequest variable. This gets the php file path.
*/
var phpFileRequest:URLRequest = new URLRequest("php/controlpanel.php");
/*
this allows us to use the post function in php
*/
phpFileRequest.method = URLRequestMethod.POST;
/*
attach the php variables to the URLRequest
*/
phpFileRequest.data = phpVars;
/*
create a new loader to load and send our urlrequest
*/
var phpLoader:URLLoader = new URLLoader();
phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
phpLoader.addEventListener(Event.COMPLETE, showResult);
/*
now lets create the variables to send to the php file
*/
phpVars.systemCall = "checkLogin";
phpVars.username = username.text;
phpVars.password = password.text;
/*
this will start the communication between flash and php
*/
phpLoader.load(phpFileRequest);
}
public function showResult (event:Event):void {
var result_text:TextField = new TextField();
addChild(result_text);
/*
this autosizes the text field
***** You will need to import flash's text classes. You can do this by adding:
import flash.text.*;
...to your list of import statements
*/
result_text.autoSize = TextFieldAutoSize.LEFT;
/*
this gets the output and displays it in the result text field
*/
result_text.text = "" + event.target.data.systemResult;
}
}
}
I'm not exactly sure where to put all those instances for my button movieclip and text field but when I ran my program, I got this error.
Error: Error #1023: Stack overflow occurred.
at flash.display::DisplayObject()
at flash.display::InteractiveObject()
at flash.text::TextField()
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
at login()
I tried searching answers that I could understand but to no avail. Any help would be appreciated, thank you.
Upvotes: 0
Views: 228
Reputation: 13522
You seem to be creating an instance of the login
class and adding it to itself which is causing the infinite recursion in the login constructor.
var login_form:login = new login();
You should initialize the login class from another object and add it to the stage just once.
Upvotes: 0
Reputation: 9839
You got the Stack overflow
error because you are creating an infinite loop of instantiating your login
class using var login_form:login = new login();
in its constructor, so every instance of that class will create another instance.
You should instantiate your class only when/where you want to insert it, for example, in the main timeline, or the document class, ..., or just by dropping it directly to the stage.
But before instantiating the login
class, you should create it correctly. For that, you can add your objects (Buttons, MovieClips, TextFields, ...) manually in your IDE by dropping them to the stage of your MovieClip, or by code using for example :
var username:TextField = new TextField();
addChild(username);
var password:TextField = new TextField();
addChild(password);
// LoginButton here is the AS linkage of a MovieClip/Button in the library
var login_button:LoginButton = new LoginButton();
addChild(login_button);
this operation is usually done once, then you can use your objects like this for example :
var user_name:String = username.text;
if(password.text != ''){ /* ... */ }
login_button.x = 30;
As you are beginner, you can start Learning ActionScript 3 here.
Hope that can help.
Upvotes: 2