ForumsProgramming ForumIncorrect number of arguments

8 14244
alex57834
offline
alex57834
88 posts
Nomad

Alright got this error
Classes\\Document.as, Line 9 1136: Incorrect number of arguments. Expected 1.
and this.
Classes\\Document.as, Line 1 5000: The class 'Document' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.

here are the classes
the document class is the document class

package {

import flash.display.MovieClip;

public class Document {

public function Document()
{
avatar();
trace("Document Class Working"
}

}

}


and the avatar class

package {

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;

public class avatar extends MovieClip {

private var _vx:Number;
private var _halfWidth:Number;
private var previousKey:uint;

public function avatar():void
{
this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}

private function onAddedToStage(event:Event):void
{
this._vx = 0;
this._halfWidth = this.width / 2;
this.previousKey = Keyboard.RIGHT;

//add Event Listeners

stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyboardDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyboardUp);
this.addEventListener(Event.ENTER_FRAME, onEnter);
this.addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
}

private function onRemovedFromStage(event:Event):void
{
this.removeEventListener(Event.ENTER_FRAME, onEnter);
this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
this.removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
}
private function onKeyboardDown(event:KeyboardEvent):void
{

//this tells how mnay to go side to side and tells it how to move
var currentKey:uint = event.keyCode;

if (event.keyCode == Keyboard.LEFT)
{
if (currentKey != _previousKey)
{
_previousKey = currentKey;
this.scaleX *= -1;
}

_vx + -4;
}

if (event.keyCode == Keyboard.RIGHT)
{
if (currentKey != _previousKey)
{
_previousKey = currentKey;
this.scaleX *= -1;
}
_vx + 4;
}
}
private function onKeyboardUp(event:KeyboardEvent):void
{
if (Keyboard.keyCode == Keyboard.LEFT || Keyboard.keyCode == Keyboard.RIGHT)
{
_vx = 0;
}
}
private function onEnter(event:Event):void
{
this.x += _vx;
checkStageBoundries();
}
private function checkStageBoundries():void
{
//get if statements to show if its going off the stage and stop it

if (this.x - halfWidth < 0)
{
this.x = 0 + halfWidth;
}
else if (this.x + halfWidth < 0)
{
this.x = stage.stageWidth - halfWidth;
}
}

}

}

  • 8 Replies
weirdlike
offline
weirdlike
1,299 posts
Prince

Document.as
public class Document extends MovieClip

Incorrect number of arguments. Expected 1.
I think this
avatar();

alex57834
offline
alex57834
88 posts
Nomad

so that is the argument avatar();

alex57834
offline
alex57834
88 posts
Nomad

How do u actually run a class?

weirdlike
offline
weirdlike
1,299 posts
Prince

the argument goes inside

avatar("argument&quot;

public function avatar("argument&quot:void
{
this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}

yours shows as no argument is needed but apparently it need's one, if I ran your code I could get a better understanding of whats going on

weirdlike
offline
weirdlike
1,299 posts
Prince

How do u actually run a class?


on your fla file click on File>Action Script Settings...

then in the document class box enter in the name of your main document .as file

I have a kit I made HERE
weirdlike
offline
weirdlike
1,299 posts
Prince

I think this would better suit you

//add the avatar class to the stage
avatar(stage);

//the s represents the stage
public function avatar(s):void
{
//you dont need added to stage instead do this
s.addEventListener(WHATEVER LISTENER, NAME OF LISTENER);
}

alex57834
offline
alex57834
88 posts
Nomad

thank you

weirdlike
offline
weirdlike
1,299 posts
Prince

I just hope that I explained it well enough so it is understandable

Showing 1-8 of 8