Forums → Programming Forum → Incorrect number of arguments
8 | 14142 |
- 8 Replies
Showing 1-8 of 8
8 | 14142 |
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;
}
}
}
}
Document.as
public class Document extends MovieClip
Incorrect number of arguments. Expected 1.
I think this
avatar();
the argument goes inside
avatar("argument"
public function avatar("argument":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
How do u actually run a class?
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);
}
I just hope that I explained it well enough so it is understandable
You must be logged in to post a reply!