Forums

ForumsProgramming Forum

Incorrect number of arguments

Posted Oct 18, '13 at 8:03am

alex57834

alex57834

89 posts

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;
}
}

}

}

 

Posted Oct 18, '13 at 1:49pm

weirdlike

weirdlike

714 posts

Moderator

Document.as
public class Document extends MovieClip

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

 

Posted Oct 18, '13 at 1:59pm

alex57834

alex57834

89 posts

so that is the argument avatar();

 

Posted Oct 18, '13 at 2:03pm

alex57834

alex57834

89 posts

How do u actually run a class?

 

Posted Oct 18, '13 at 2:04pm

weirdlike

weirdlike

714 posts

Moderator

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

 

Posted Oct 18, '13 at 2:07pm

weirdlike

weirdlike

714 posts

Moderator

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
 

Posted Oct 18, '13 at 2:30pm

weirdlike

weirdlike

714 posts

Moderator

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);
}

 

Posted Oct 18, '13 at 3:31pm

alex57834

alex57834

89 posts

thank you

 

Posted Oct 18, '13 at 4:06pm

weirdlike

weirdlike

714 posts

Moderator

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

 
Reply to Incorrect number of arguments

You must be logged in to post a reply!