PDA

View Full Version : Problem adding listener to movieclip grabbed from stage



rengiotheleo
December 15th, 2008, 05:59 PM
Hello people i'm have a issue with this errorTypeError: Error #1009: Cannot access a property or method of a null object reference.

The error occurs from a display object i assign to a variable in my class using:

submitBtn = this.getChildByName('submitButton') as MovieClip

then i add Eventlistener

submitBtn.addEventListener(MouseEvent.CLICK,submis sion);

On click of it returns that error. Any suggestions


Thanks

creatify
December 15th, 2008, 06:17 PM
what does your submission function look like?

rengiotheleo
December 15th, 2008, 06:19 PM
hey this is the entrie class


package classes
{

import flash.display.MovieClip;
import flash.events.MouseEvent;
import classes.Validation;

public class Login extends MovieClip
{

private var regName:MovieClip;
private var regPhone:MovieClip;
private var regEmail:MovieClip;

private var submitBtn:MovieClip;
private var validate:Validation;

public function Login(){

if( this.getChildByName('submitButton') != null){

trace('Found');
trace(this.getChildByName('submitButton'));

}


regName = this.getChildByName('registerName') as MovieClip;
regPhone = this.getChildByName('registerPhone') as MovieClip;
regEmail = this.getChildByName('registerEmail') as MovieClip;
submitBtn = this.getChildByName('submitButton') as MovieClip;

submitBtn.addEventListener(MouseEvent.CLICK,submis sion);
submitBtn.useHandCursor = true
}

public function makeTest():void{

trace('Hello');
}

public function submission(evt:MouseEvent):void{

var status:String = 'success';

if(validate.checkPhone(regName.holder_txt.text) == false){
registerPhone.holder_txt.text = 'Please enter valid phone number';
status = 'fail';
}

if(validate.checkEmail(regEmail.holder_txt.text) == false){
registerEmail.holder_txt.text = 'Please enter valid email';
status = 'fail';
}

if(validate.checkText(regName.holder_txt.text) == false){
registerName.holder_txt.text = 'Please enter valid name';
status = 'fail';
}

if(status == 'success'){
MovieClip(parent).setLoginData(registerName.holder _txt.text, registerEmail.holder_txt.text, registerPhone.holder_txt.text);
}
}

public function closeSection():void{

submitBtn.removeEventListener(MouseEvent.CLICK,sub mission);
}
}

}

thanks for the time.

creatify
December 15th, 2008, 06:26 PM
it's a problem in your submission method...

It think it may be where you're using:
registerPhone
registerName
etc.

you should be using
regPhone
regEmail
etc.

it's not recognizing registerPhone as a property of that class - I believe anyhow. can always place a number of traces in that submission method, every couple lines - thats the dirty way to pin down where the 1009 error is - same thing I suggest here (http://www.actionscript.org/forums/showthread.php3?t=191902)

rengiotheleo
December 15th, 2008, 06:41 PM
thanks for the help, i renamed those vars and i think the main reason was that the validate function was not instanciated:

validate = new Validation();

and the submit was trying to use it

public function submission(evt:MouseEvent):void{

trace(TextField(regName['holder_txt']).text);

var statusItem:String = new String('success');

if(validate.checkPhone(TextField(regPhone['holder_txt']).text) == false){
TextField(regPhone['holder_txt']).text = 'Please enter valid phone number';
statusItem = 'fail';
}

if(validate.checkEmail(TextField(regEmail['holder_txt']).text) == false){
TextField(regEmail['holder_txt']).text = 'Please enter valid email';
statusItem = 'fail';
}

if(validate.checkText(TextField(regName['holder_txt']).text) == false){
TextField(regName['holder_txt']).text = 'Please enter valid name';
statusItem = 'fail';
}

if(statusItem == 'success'){
MovieClip(parent).setLoginData(TextField(regName['holder_txt']).text, TextField(regEmail['holder_txt']).text, TextField(regPhone['holder_txt']).text);
//MovieClip(parent).nextStep('step1');
}
}