PDA

View Full Version : Argument Error... Need some help, please



preciousroy
February 17th, 2009, 12:51 AM
I'm getting the following output: "ArgumentError: Error #1063: Argument count mismatch on AccordionMenu(). Expected 2, got 0."

While I'm a noob, I understand what it's telling me, but can't figure out for the life of me why it thinks it is getting 0 arguments.

I'm trying to get an accordion menu to load on a mouse click with info loaded from an XML file. The menu I'm using can be found here: http://www.blog.noponies.com/archives/39

It's a cool menu, but it's set up with multiple classes. He's got a custom class for the accordion menu, a custom class for an XML loader, and finally custom class (that he's using as the document class) to load in the other classes. (He also using TweenLite).

Anyway, I've nixed the latter two and am just trying to use the accordion menu as my document class and handle everything else via the ActionScript panel in the timeline. That's where the code below is in my fla file.

A couple of things, the document that I'm pulling my XML from is called "map.xml." So "map.XML.button.country.club" is part of the dot-syntax of my XML file.

The original accordion menu was set up to take 3 arguments (a title, an image, and an action). I edited the custom class of the AccordionMenu file to get rid of the action, so it's just looking for 2 arguments now.

The problem is, it thinks it's getting 0. There's a line in the code right below the //comment: "load the menu content...." where I bring in the accordion class, and from what I can figure, I've given it two arguments:

1) "loader.content"
2) "mapXML.button[i].country.club[p].@name"

So, any help on why this is giving me the error that it's not getting 2 arguments?

Thanks in advance and sorry for the length, but, like I say, I'm new to this. So I'm trying to err on the side of clarity.


import flash.events.MouseEvent;

var dynFileName:String
var xmlLoader:URLLoader = new URLLoader();
var mapURL:URLRequest = new URLRequest("map.xml");
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
xmlLoader.load(mapURL);

//vars for the loop to load the names into the accordion menu
var p:int = 0;
var menuy:int = 0;
var loader:Loader;

var mapXML:XML = new XML();
mapXML.ignoreWhitespace = true

function xmlLoaded(evt:Event):void{
mapXML = XML(xmlLoader.data);//load XML into data
trace(mapXML.button.length());
}

stage.addEventListener(MouseEvent.CLICK, reportClick);

function reportClick(event:MouseEvent):void
{
dynFileName = (event.target.name);
trace("Button Instance Name = " + dynFileName);
//trace(mapXML.button.@name);

for (var i:Number = 0; i <mapXML.button.length(); i++){

if(dynFileName == mapXML.button[i].@name){
trace(mapXML.button[i].country.club.@name);
trace("Match");

//Building the accordion menu

function loadThumbs():void {
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.IN IT, initListener);
loader.load(new URLRequest(String(mapXML.button[i].country.image.text()[p])));

function initListener(e:Event):void {
//load the menu content "AccodrionMenu.as" is the document class
var newMenu:AccordionMenu = new AccordionMenu(loader.content, mapXML.button[i].country.club[p].@name);
addChild(newMenu);
p++;
if (p<mapXML.menuitem.length()) {
loadThumbs();//create loop
}
}
}
}
else{
trace("No match");
}
}
}

Krilnon
February 17th, 2009, 01:54 AM
am just trying to use the accordion menu as my document class

That's the problem, I bet. When you use a class as the document class, you don't explicitly create an instance of that class in code. However, an AccordionMenu still needs to be created behind the scenes. Flash will try to create an AccordionMenu, but it has no way to know what it should pass as arguments, so it doesn't pass any.

You should adjust the constructor so that it doesn't need 2 arguments or change which class you use as the document class. You might just want to add default values to the constructor so that you can use it in both cases:


public function MyConstructor(someArg:String = "someConstant", someArg2:int = 4){ ... }

scottc
February 17th, 2009, 02:04 AM
You have 2 parameters passing to it... looks correct.

var newMenu:AccordionMenu = new AccordionMenu(loader.content, mapXML.button[i].country.club[p].@name);

However i'd double check to see if they are not null or something wierd, also read this thread http://www.kirupa.com/forum/showthread.php?t=313070 incase you have used it elsewhere with no parameters without noticing.

preciousroy
February 17th, 2009, 09:10 AM
Thanks for the reponses. Still can't get it to work.

Krinlon, while i sort of understand what you're saying, I don't think that will work in this situation.

What I've got is a map. When you click on a country, that generates the Accordion menu, and the values of the menu (the title bars and the thumbs that go in in) are specific to that county. That means two things (I think):

1) I have to have code that tells AS when to generate the menu (on the mouse event). So, if the Accodion Menu isn't my document class, how do I do that?

2) I can't just pass default values for arguments to the constructor as the whole point is for the menu to generate 'dynamically' (or based on the values fed to it from the XML when a country is clicked).

And thanks scottc. Debugging the movie doesn't give me any additional information.

Thanks again for the suggestions. Any others are welcome.

dail
February 17th, 2009, 03:16 PM
Well, the way its set up in the demo is that the accordion is built once the XML has loaded. Your method of using a mouse event should work to create the menu.

You shouldn't set your document class as as the accordion class itself, rather have an instance of the accordion menu in your document class, which was what Krilnon was saying. I would just set it up like how it is in the demo, but use a mouse click to load the menu, rather than waiting for your XML to load.

This accordion file is kinda crappy really, I should clean it up.

preciousroy
February 17th, 2009, 03:19 PM
Good news. I'm not longer getting my argument error. Or any of the other errors. Bad news. I don't know what I did. Following Krilnon's advice, I removed the Accordion Menu as the document class and I was still getting errors. Then I simply quit Flash. I shut down for a few hours to do a few other things. I restarted my computer, launched the .fla file and when I went to Test Movie, the original Argument Error no longer appeared. And it made it all the way through rendering the movie without any errors at all. Yippee!.

But the menu didn't work. Boo. I worked in a few trace statements and can tell you that things are going off the rails. Right in the above code where it reads:

"//Building the accordion menu

function loadThumbs():void {"

If I put a trace statement before the function, it loads. If it goes after, no dice.

So, seeing how the above code isn't a complete disaster, any thoughts on why the loadThumbs function isn't going?

Thanks again.

dail
February 17th, 2009, 03:30 PM
You don't ever seem to call the loadThumbs function.

preciousroy
February 17th, 2009, 03:30 PM
Dail: Might be "crappy" but it's perfect for what I'm trying to do.

I've cleaned things up a bit and tried to streamline it, so I don't need to use the as3accord.as and the loadXml.as classes you included. Hence my problems.

Still new to this and can only work on it here and there... I'm only at the point where I can make sense of what you were trying to do at each step, and change things to suit my needs. Obviously not with 100% success but glad you chimed in.

preciousroy
February 17th, 2009, 03:33 PM
Dail:

Here's the most recent version of the code from that section:

function loadThumbs():void {
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.IN IT, initListener);
loader.load(new URLRequest(String(africaXML.button[i].country.image.text()[p])));

function initListener(e:Event):void {
//load the menu content
var newMenu:AccordionMenu = new AccordionMenu(loader.content, africaXML.button[i].country.club[p].@name);
addChild(newMenu);
p++;
if (p<africaXML.button[i].country.club.length()) {
loadThumbs();




Isn't the last line calling the loadThumbs function?

dail
February 17th, 2009, 05:31 PM
It does call it yes, but you never load the first image, to make that init listener fire, so that if clause that creates a loop to load all the images in your XML never runs. I mean, its a loop, but the loop never gets started.

preciousroy
February 17th, 2009, 06:42 PM
Two things: And I know the first question is rather ridiculous, but where am I NOT loading the first image? I know you can't point out what's not there, but maybe some help in terms of what is lacking.

Second: Well, those functions are nested inside a larger loop, so it should be looping, right? Or maybe I'm not understanding you.

This is an entirely new language to me (hadn't done any kind of scripting before I started the project I'm working on now). I am amazed at what is available as free resources and generally how helpful the developer community is. So, any help on top of that is appreciated. But if I might ask an additional favor... Could you pretend that I'm an idiot who barely speaks your language when helping. I am more than willing to work through things as best I can—I turned cartwheels when I got the XML to load and had the code correctly trace the names were generated properly from the mouse click—so the better I understand where your trying to get me pointed the more I can work in that direction. I hope that doesn't sound ungrateful. Again, I am generally amazed at how helpful people are w/r/t AS3 and thankful for it.

dail
February 17th, 2009, 09:43 PM
Its difficult to tell, try posting your code in [ as ] [ /as ] brackets so its formatted correctly.

I'd structure what you are doing differently, you shouldn't have the init event handler etc nested in a loop, nor the loadThumbs method. That for loop will run much quicker than you can load in your thumbnails. A better solution would be to parse your XML into a smaller chunk of results, that contains only the particular matches you need, then once you have that, use the smaller XML chunk as data for the loadThumbs method, removing it from the loop you currently have.


Look up EX4 filtering, or predicate to filter your XML down to a smaller set of matches, something like;


var myXMLList:XMLList = mapXML.*;
var subResults:XMLList;
var p:int = 0;

function reportClick(event:MouseEvent):void {
subResults = myXMLList.*.(mapXML.button[i].@name == event.target.name);
p = 0;
loadThumbs()
}

function loadThumbs():void {
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.IN IT, initListener);
loader.load(new URLRequest(String(subResults.button[p].country.image.text()[p])));
}


function initListener(e:Event):void {
//load the menu content "AccodrionMenu.as" is the document class
var newMenu:AccordionMenu = new AccordionMenu(loader.content, mapXML.button[i].country.club[p].@name);
addChild(newMenu);
p++;
if (p<mapXML.menuitem.length()) {
loadThumbs();//create loop
}else{
//all done
}


Thats just psuedo code, untested..

preciousroy
February 18th, 2009, 01:51 AM
Thanks Dail. I'll give this a try in the morning.

I had started with a completely different approach. Basically with my XML loaded, why wasn't I just calling the Accodion Menu class and supplying the two arguments.

It was much less code, but it was giving me the following error:

"ReferenceError: Error #1069: Property height not found on String and there is no default value.
at AccordionMenu()
at Africa_Second_under_construction_fla::MainTimeline/reportClick()"

I'll pick back up again with the suggested above and see if I can't get it working. Thanks for all the help (and also for the tip formatting, will do in the future)