02-22-2012 04:06 PM
I created a save button and added an eventlistener to run the saveAs() when the button is clicked but I'm getting
Error #1063: Argument count mismatch on views::TxtView/saveAs(). Expected 0, got 1.
I haven't supplied any arguments.
In my init()
...
var saveAsFileBtn:IconButton = new IconButton();
saveAsFileBtn.setIcon("../icons/saveas.png");
saveAsFileBtn.width=100;
saveAsFileBtn.x=saveFileBtn.width+71;
saveAsFileBtn.sizeMode = SizeMode.BOTH;
saveAsFileBtn.sizeUnit = SizeUnit.PIXELS
saveAsFileBtn.addEventListener(MouseEvent.CLICK, saveAs);
...
then
private function saveAs():void
{
trace("Save as");
var fileChooser:File;
if (currentFile)
{
fileChooser = currentFile;
}
else
{
fileChooser = File.documentsDirectory.resolvePath('untitled.html
}
fileChooser.browseForSave("Save As");
fileChooser.addEventListener(Event.SELECT, saveAsFileSelected);
}
The debugger stops when the Save As button is clicked. When I use regular spark buttons I have no problem.
Solved! Go to Solution.
02-22-2012 04:10 PM
All event handlers will get at least the event object, so you'd have to define it as
function saveAs(e:Event):void
even if you plan to ignore the object.
02-22-2012 04:10 PM
Hey RapsFan,
Since you are calling the function as a listener on an event, its sending in the event as an argument into the function. so its almost invisible but it is being sent. Your workaround is to make a listener function that calls that save as function or just turn the save as function into a listener function like so:
private function saveAs(e:MouseEvent):void
{
trace("Save as");
var fileChooser:File;
if (currentFile)
{
fileChooser = currentFile;
}
else
{
fileChooser = File.documentsDirectory.resolvePath('untitled.html ')
}
fileChooser.browseForSave("Save As");
fileChooser.addEventListener(Event.SELECT, saveAsFileSelected);
}
good luck!
02-22-2012 04:46 PM
Thanks guys. Some things seem so obvious after someone else points them out ![]()
02-22-2012 04:54 PM
02-22-2012 05:44 PM
Excellent point peter and JRab. I am calling it manually as well so I'm going to use the wrapper idea, only because I don't know how to set an event as null. Can you give an example peter?
02-22-2012 06:06 PM
Ahh now I see. You can actually pass null as a parameter in place of an event!