0

I have the following code so I can use the var "qst" in another function. But when I run it I get an error

"1136: Incorrect number of arguments. Expected 1" for this line button();

Do I have to put an argument in button(); for this to work? Many thanks

var myDateDay:Date = new Date();
var dayNumber:int = myDateDay.day;
var qst:XML;
var qstLoader:URLLoader = new URLLoader();
qstLoader.load(new URLRequest("default.qst"));
qstLoader.addEventListener(Event.COMPLETE, processQST);

// Process QST file;
function processQST(e:Event):void {
qst = new XML(e.target.data);
trace(qst);
button();
}

myButton.addEventListener(MouseEvent.CLICK, button);
function button(event:MouseEvent):void {
var question:XMLList = qst.question.(@day == dayNumber).text;
trace(question);
}

1 Answer 1

1

Since you want your "button" to be both called from outside and to react on events, you need to assign it a parameter of type Event. So, either call it like button(null); or make an adjust to your declaration, like this:

function button(event:MouseEvent=null):void {...}

and call it like a function with zero parameters.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you @Vesper. I will try that. I would like the var "qst" to be available for use outside the processQST function and this is what I have found that may do that.
It seems that when I use button(null); it doesn't wait for the button to be clicked, but runs right through the second function.
In this case your process is two-phased, first you load the qst, second you press the button. You can play with its "enabled" property, internal flag, availability of qst's data or adding listener only in processQST function. Either might work in your case, but you need to clarify it. Also, if you actually receive correct data in button() function, then your QST is available, otherwise this needs more clarification as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.