Reputation: 91
So I was trying to make a AvoiderGame tutorial for my YT, and I found a glitch with the program. (It was telling me the Timer object accepts 0 parameters)
Then I thought that I might have missed a bracket or something somewhere which caused the error, but for now, it seems like a Flash Professional Glitch
INFORMATION:
File: Enemy.as (linked to the "Enemy" movieclip symbol in the main.fla
file)
package{
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Enemy extends MovieClip{
private var speeds:Array = new Array();
private var counter:Timer = new Timer(1); <-- Line 8
private var speed:int = 0;
public function Enemy(xPos:int, yPos:int, speeds:Array){
x = xPos;
y = yPos;
this.speeds = speeds;
initalize();
counter.start();
counter.addEventListener(TimerEvent.TIMER, update);
}
protected function initalize(){
speed = speeds[0] + Math.round(Math.random()*(speeds[1] - speeds[0]));
}
protected function update(e:TimerEvent){
y += speed;
}
public function setPos(xVal:int, yVal:int){
x = xVal;
y = yVal;
}
public function movePos(xVal:int, yVal:int){
x += xVal;
y += yVal;
}
}
}
(I replaced my username with "User" so people wont know my real name)
This Code gave me the following errors:
C:\Users\User\Desktop\Flash Stuff\Avoider DeluX\Enemy.as, Line 8, Column 35 1136: Incorrect number of arguments. Expected 0.
C:\Users\User\Desktop\Flash Stuff\Avoider DeluX\Enemy.as, Line 8, Column 35 1136: Incorrect number of arguments. Expected 0.
(yes, the errors did appear 2 times)
Upvotes: 1
Views: 57
Reputation: 456
I think it's the problem with parameter . One thing i have noticed is timer accepts 2 params. First one is delay which is in milliseconds. Second one is repeatCount that's optional
As the docs says
A delay lower than 20 milliseconds is not recommended.
So i would recommend to use a number more than 20 milliseconds or 1000 for one second.
Upvotes: 0
Reputation: 56462
It make me think that you may another Timer
class colliding in your namespace. Try precising the full name each time:
private var counter:flash.utils.Timer = new flash.utils.Timer(1);
Upvotes: 1