A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Catch 22....wrong number of arguments or cannot reference null object

  1. #1
    Member
    Join Date
    Jul 2005
    Posts
    63

    Catch 22....wrong number of arguments or cannot reference null object

    I am having trouble creating arrow buttons to move from one frame to the next in my fla file. In addition to my page forward/page backward buttons, I also have a table of contents off to the side. I would like to create a function that will control the buttons at the beginning, and refer to them in subsequent frames so that the forward and back buttons will work even when that frame is jumped to. I am experiencing an expected number of arguments error when I use the code without referencing a null value...however, when I try to set the function to null, I get an error that states that I cannot reference a method or object with a null reference....can anyone tell me where to go to fix this problem?

    Code:
    function arrows(e:MouseEvent=null):void {
    	nextArrow.addEventListener(MouseEvent.CLICK, nextArrowAdvance);
    	nextArrow.buttonMode = true;
    	function nextArrowAdvance(e:Event):void {
    		nextFrame();
    	}
    	prevArrow.addEventListener(MouseEvent.CLICK, prevArrowBack);
    	prevArrow.buttonMode = true;
    	function prevArrowBack(e:Event):void {
    		prevFrame();
    	}
    }
    Attached Files Attached Files

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Your explanation makes no sense. Seriously. I have no idea what you mean by "set the function to null".

    First thing's first. Get those nested functions out of the arrows function. There's no reason for them to be nested.

    Then, post each code version you've tried and associated full error messages. Is the code above the one giving the null error or the one giving the unexpected number of arguments error?
    When are you calling the arrows function? What are you passing to it?

    This may all be in the fla you posted, but not all of us have flash to open it.

    This should be sufficient, on the first frame:
    Code:
    nextArrow.addEventListener(MouseEvent.CLICK, nextArrowAdvance);
    nextArrow.buttonMode = true;
    function nextArrowAdvance(e:Event):void {
    	nextFrame();
    }
    
    prevArrow.addEventListener(MouseEvent.CLICK, prevArrowBack);
    prevArrow.buttonMode = true;
    function prevArrowBack(e:Event):void {
    	prevFrame();
    }
    That is, there should be no reason you need an arrows function if you want the buttons set up from the beginning.

  3. #3
    Juvenile Delinquent CVO Chris's Avatar
    Join Date
    Jul 2002
    Location
    Ulster, UK
    Posts
    520
    Am I right in thinking that if you click on the next arrow then it will go to the next frame (and/or section)? If so; can't you just do the following?

    Actionscript Code:
    // create a variable for what section you're on
    var section:Number;

    // listeners for the arrows
    nextArrow.addEventListener(MouseEvent.CLICK, nextSection);
    prevArrow.addEventListener(MouseEvent.CLICK, prevSection);

    // if the next arrow is pressed then if it's not on the last section then
    // it will jump to next frame
    function nextSection(e:MouseEvent):void {
        if (section =< 4) {
            section = section + 1;
            gotoAndStop(nextFrame);
        }
    }

    // and if the previous arrow is pressed then if it's not on the first
    // section then it jump to previous frame
    function prevSection(e:MouseEvent):void {
        if (section => 1) {
            section = section - 1;
            gotoAndStop(prevFrame);
        }
    }

    // you'll also have to go in your other functions and set the section variable
    // in each onein case the user uses the menu instead of the arrows like:
    function courseIntroAdvance(e:Event):void {
        gotoAndPlay(2);
        section = 1;
    }

    function courseObjectivesAdvance(e:Event):void {
        gotoAndPlay(3);
        section = 2;
    }
    Last edited by CVO Chris; 06-01-2010 at 03:40 PM.

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    function arrows(e:MouseEvent=null):void {
    	if (nextArrow!=null) {
    		nextArrow.addEventListener(MouseEvent.CLICK, nextArrowAdvance);
    		nextArrow.buttonMode=true;
    
    	}
    	if (prevArrow!=null) {
    		prevArrow.addEventListener(MouseEvent.CLICK, prevArrowBack);
    		prevArrow.buttonMode=true;
    
    	}
    }
    function nextArrowAdvance(e:Event):void {
    	nextFrame();
    }
    function prevArrowBack(e:Event):void {
    	prevFrame();
    }

  5. #5
    Member
    Join Date
    Jul 2005
    Posts
    63
    Thank you dawsonK! that worked!

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