dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: What is wrong with this code?

  1. #1
    Member
    Join Date
    Mar 2009
    Posts
    62

    What is wrong with this code?

    I'm getting:TypeError: Error #1009: Cannot access a property or method of a null object reference. at CatProcess/validateAge()

    When I attach the textbox manually without the function, it works fine though

    PHP Code:

    package
    {

    public class{
    var 
    userName_iBox:TextInput;
            var 
    userAge_iBox:TextInput;
            var 
    test_iBox:TextInput;

    public function(
    createInputBox(userAge_iBox,197,87,FocusEvent.FOCUS_IN,clearTxt,FocusEvent.FOCUS_OUT,validateAge)
    }

    function 
    createInputBox(varName:TextInput,moveX:Number,moveY:Number,...eventList){
                
    varName= new TextInput();
                
    varName.move(moveX,moveY);
                
    addChild(varName)
                if (
    eventList.length>0){
                    
    varName.addEventListener(eventList[0],eventList[1])
                    if(
    eventList.length>2){
                        
    varName.addEventListener(eventList[2],eventList[3])
                    }
                }
                
            }

    function 
    validateAge(e:Event)
            {
                
    userAge Number(userAge_iBox.text);
                    if(
    isNaN(userAge)) {
                        
    output_txt.text "You have entered a string, please try again";
                        
    output_txt.setTextFormat(validate_frmt);
                    
                    }else if(
    userAge_iBox.text==""){
                        
    output_txt.text "You haven't entered anything in the box, please try again"
                        
    output_txt.setTextFormat(validate_frmt);
                    } else {
                        
                        
    chkAge();
                    }
            }
    }


  2. #2
    Member
    Join Date
    Mar 2009
    Posts
    62
    I've worked out what it says is null - userAge_iBox...but that has been added to the stage so how can it be null?

  3. #3
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    when does validateAge get called ? Because if , userAge_iBox.text is empty , meaning theres nothing in the textfield, then the string it returns is empty , and you are then casting an empty string into a number , which i would expect to then be null.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center