Skip to main content
Participating Frequently
February 14, 2010
Question

1136: Incorrect number of arguments. Expected 1

  • February 14, 2010
  • 2 replies
  • 1050 views

hello to all.

am new to this and am trying to call a function from a .as file and am getting this error

.AS FILE

package
{
    import flash.events.MouseEvent;
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.display.SimpleButton
   
    public class displayNumbers extends Sprite
    {
        private var result_txt:TextField;
        private var display_txt:TextField;
        private var showSign_txt:TextField;
        private var zero_btn:SimpleButton;
       
        public function displayNumbers ():void
        {
        
            zero_btn.addEventListener(MouseEvent.CLICK, callZero);
        }     
       
       
//-----------------ADD NUMBER ZERO--------------------------------------------

        public function callZero(e:MouseEvent):void
        {
            result_txt.text = "";
            result_txt.text= String(display_txt.maxChars - display_txt.length);
            if (result_txt.text > "1")
            {
                display_txt.appendText("0");
                showSign_txt.appendText("0");        
            }
            else
            {
                result_txt.visible = true;
                result_txt.text = "MAX INPUTS";
            }//if else statement
        }//function callZero
    }//class displayNumbers
}//package

The ACTION FILE

import displayNumbers;
var noOne:displayNumbers = new displayNumbers();

noOne.callZero();

Thank you in advanced!

This topic has been closed for replies.

2 replies

fh84Author
Participating Frequently
February 14, 2010

what i am trying to do is by pressing zero_btn which is an object in the library to print a number in the dynamic text box ( result_txt ) which is also an existing object in the library and on stage.

my knowledge in actionscript is not much and messing with .as files is totally new to me!

so by giving you to understand what am trying to do would be much easier for you to help me as well. then thing is that this code when i locate into to .fla file works fine.

.as file

package
{
    import flash.events.MouseEvent;   
    import flash.display.Sprite;   
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.display.SimpleButton
   
    public class displayNumbers extends Sprite
    {
       
        public function displayNumbers ()
        {
            zero_btn.addEventListener(MouseEvent.CLICK, callZero);
        }     
       
        public function callZero(e:MouseEvent):void
       
        { 
            result_txt.text = "";
            result_txt.length = display_txt.maxChars - display_txt.length;
            if (result_txt.length > 1)
            {
                display_txt.appendText("0");
                showSign_txt.appendText("0");        
            }
            else
            { 
                result_txt.visible = true;
                result_txt.text = "MAX INPUTS";
            }
        }//function callZero
    }//class displayNumbers
}//package

the action:

import displayNumbers;

Ned Murphy
Legend
February 14, 2010

The problem is arising from this line: noOne.callZero();

Your callZero function is expecting an event argument.  The way around this is to define the callZero finction using...

    public function callZero(e:MouseEvent=null):void

fh84Author
Participating Frequently
February 14, 2010

thank you for the reply

however i did what you just said, now i do not have any compired errors but the output says:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at displayNumbers()
    at Assignment_fla::MainTimeline/frame1()

Ned Murphy
Legend
February 14, 2010

That will be a different error...  The 1009 error indicates that one of the objects being targeted by your code is out of scope.  This could mean that the object doesn't have an instance name, or the instance name is mispelled, or it does not exist in the frame where that code is trying to talk to it.

If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.