PDA

View Full Version : Class doesn't recognize extra arguments


andy killer
10-27-2009, 11:55 AM
What up people?!

I have this "small" problem.
I'm building a small website. It's external class based and the ideia is to load the menus and content externally, by XML.

I'm using as base code an example from "Learning Actionscript 3.0 Book", from Rich Shupe and Zevan Rosser.

My class structure, I believe, is working well, but somehow one of the classes is not working properly.

The problem happens in line 21 and line 27. The error is the following:

NavigationBar: line 21 (and 27);
1136: Incorrect number of arguments. Expected 0.
source: var menuBtn:MenuButtonMain = new MenuButtonMain( _navData.button[i].@label);

This is my AS3 class. It intereacts with more classes, so if you need the other classes to check, feel free to ask.


package app.gui{
import flash.display.Sprite;
import flash.filters.DropShadowFilter;

public class NavigationBar extends Sprite {
private var _app:Sprite;
private var _buttonSpacing:int;
private var _hline:HLineThick;
private var _navData:XMLList;

public function NavigationBar(app:Sprite, navData:XMLList) {
_app = app;
_navData = navData;
_buttonSpacing = _navData.@spacing;
build();
}

private function build():void {

for (var i:int; i < _navData.button.length(); i++) {
var menuBtn:MenuButtonMain = new MenuButtonMain( _navData.button[i].@label);
menuBtn.x = 20 + (menuBtn.width + _buttonSpacing) *i;
menuBtn.y = 75;

var subMenuButtonNum:uint = _navData.button[i].project.length();
for (var j:uint = 0; j < subMenuButtonNum; j++) {
var subMenuButton:MenuButtonSub= new MenuButtonSub( _app, _navData.button[i].project[j]);
subMenuButton.y = ((subMenuButton.height -2) * j);
menuBtn.subMenu.addChild(subMenuButton);
}
addChild(menuBtn);
}
_hline = new HLineThick();
_hline.y=100;
_hline.mouseEnabled=false;
addChild(_hline);

var ds:DropShadowFilter = new DropShadowFilter();
ds.angle=45;
ds.distance=5;
ds.alpha=0.5;
filters=[ds];
}
}
}


Thanks for the help ;-)

xty
10-27-2009, 02:46 PM
Hi
What this error is saying to me is that the MenuButtonMain class is not expecting you to pass it the variable for the label. I'm guessing without being able to see that classes structure. What if you tried this:

var menuBtn:MenuButtonMain = new MenuButtonMain( );
menuBtn.label = _navData.button[i].@label;

andy killer
10-27-2009, 03:38 PM
Thanks xty.

I already solved the problem. The problem was in another class. The getter and setter functions for the extra arguments of "MenuButtonMain" were marked as private instead of public.

Thanks anyway ;)