Link to home
Start Free TrialLog in
Avatar of Christopher Casey
Christopher CaseyFlag for United States of America

asked on

Flash AS3 ArgumentError: Error #1063

i get this error in the output of this flash

ArgumentError: Error #1063: Argument count mismatch on Untitled_fla::MainTimeline/onNextClick(). Expected 1, got 0.
      at QuestionForm/completeHandler()
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at flash.net::URLLoader/onComplete()

I am trying to make the MovieClip QuestionForm go to the next question ones you pick a answer.


var variables:URLVariables = new URLVariables();

buttonA.addEventListener(MouseEvent.CLICK, onAnswer);
buttonB.addEventListener(MouseEvent.CLICK, onAnswer);
buttonC.addEventListener(MouseEvent.CLICK, onAnswer);
buttonD.addEventListener(MouseEvent.CLICK, onAnswer);



function onAnswer(e:MouseEvent):void {
	switch (e.target) {
		case buttonA :


			variables.Answer="A";//or whatever you want
			variables.sendRequest="parse";

			

			// etc etc
			break;
		case buttonB :

			break;
		case buttonC :

			break;
		case buttonD :

			break;
	}

	var urlRequest:URLRequest=new URLRequest("Write-to-DB.php");
	urlRequest.method=URLRequestMethod.POST;
	urlRequest.data=variables;

	var urlLoader:URLLoader=new URLLoader  ;
	urlLoader.dataFormat=URLLoaderDataFormat.VARIABLES;
	urlLoader.addEventListener(Event.COMPLETE, completeHandler);

	//send to server
	urlLoader.load(urlRequest);
}

function completeHandler(event:Event):void {
	
	MovieClip(root).onNextClick();
	//go to next question here
	//handle the response from the server...
}

Open in new window

Untitled-3.fla
Avatar of blue-genie
blue-genie
Flag of South Africa image

i'm not getting the error you're referring but then again the code in the file you uploaded is not the same as the snippet you posted.
the error upon clicking the Next button

TypeError: Error #1010: A term is undefined and has no properties.
      at Untitled_fla::MainTimeline/onNextClick()


seems to be a problem in here

arrQuestions[currentQuestion].visible = true;
can't check what's going on with where you're pushing and adding the questionForm to the stage without the xml format but it concerns me a bit that you're adding it in a for loop.

I can't check your source file now, but what the error message is saying is that the onNextClick() function requires one argument but you are not providing it in this line...
   MovieClip(root).onNextClick();

Maybe the onNextClick() function takes an Event as an argument???  If that is the case, change it to something like this to get away with it... (It's not a good way of doing it, but that should get you going...
   function onNextClick(e:Event = null):void

If that does not work, post the code for the onNextClick function...

CyanBlue
Avatar of Christopher Casey

ASKER

O i am sorry i forgot to all the xml file and blue-genie your right i did upload the wrong flash file
Questions.xml
Untitled-3.fla
Here is the code other bit of the code.

This works it hides the questions i will have to thank other experts-exchange Genius for all the code.

what i want to do is when the user press a,b,c,d it jumps to the next questions.
//load the questions
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, onLoad);
urlLoader.load(new  URLRequest("Questions.xml"));

var arrQuestions:Array = []; 		//will contain all the questionForms for easy access
var objAnswers:Object = {};			//track all answers given
var currentQuestion:Number = -1; 	//The current displayed question

function onLoad(e:Event):void {
	var xml = new XML(e.target.data);
	var questions:XMLList = xml..Question;
	
	var questionCount:Number = questions.length();
	
	for(var i=0; i<questionCount; i++){
		//create instances of QuestionForm for each question.
		var questionForm:QuestionForm = new QuestionForm();
		
		//populate with text
		questionForm.question.text = questions[i].text();		
		questionForm.optionA.text = questions[i].Answer[0].text();
		questionForm.optionB.text = questions[i].Answer[1].text();
		questionForm.optionC.text = questions[i].Answer[2].text();
		questionForm.optionD.text = questions[i].Answer[3].text();
		//position
		questionForm.x = (stage.stageWidth /2) - (questionForm.width /2);
		questionForm.y = (stage.stageHeight /2) - (questionForm.height /2);
		
		questionForm.ID = questions[i].@id; //pulled from the id attribute in the xml file
		arrQuestions.push(questionForm); 
		addChild(questionForm);
	}
	
	hideAllQuestions();
}

function hideAllQuestions(){
	for(var i in arrQuestions) arrQuestions[i].visible = false;
}

//Next Button functionality
function onNextClick(e:MouseEvent):void{
	currentQuestion ++;
	hideAllQuestions();
	if(currentQuestion == arrQuestions.length) currentQuestion = 0; //restart - or change to show 'end screen'
	arrQuestions[currentQuestion].visible = true;
	
	traceAnswers()
}
btnNext.addEventListener(MouseEvent.CLICK, onNextClick);


//Demonsrates how to access all answers
function traceAnswers():void{
	for(var i in arrQuestions){
		if(arrQuestions[i].answer) trace("Question:" + arrQuestions[i].ID + " Answer:" + arrQuestions[i].answer);
	}
	trace("-----------");
}

Open in new window

Did you try what I have asked???  

CyanBlue
ASKER CERTIFIED SOLUTION
Avatar of CyanBlue
CyanBlue
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes changing  function onNextClick(e:Event = null):void  worked.


why ?
I put  function onNextClick(e:MouseEvent = null):void{

and it still worked again why
Thank you
It should really be MouseEvent rather than Event...  It works because of the parent-child relationship between two...  But you really need to use MouseEvent for it...

CyanBlue