I have been trying to make a gun type function and its been going really well but i have been trying to put in a reaload function and i decided to use timer class, and failed…:sad2:. So i thought id ask the gurus and hers the code.
package {
//
import flash.display.*;
import flash.events.*;
import flash.utils.Timer;
import flash.utils.Timer;
//
public class InfectedScripting extends MovieClip {
public var iGun:MovieClip = new MovieClip();
private var iBulletSpeed:Number = 65;
private var bulnum:int = 1;
private var bulletOffset:Number = 0;
private var bulletLifeTimerTotal:Number = 100;
private var reloadSpeed:Number = 2;
////////////////////////
public var myTimer:Timer = new Timer(500, reloadSpeed);
private var reloadComplete:Boolean = true;
private var bulletAngle:Number;
private var randomNum:Number;
private var spawnX:Number = iGun.x;
private var spawnY:Number = iGun.y;
private var rotationDirection:Number;
private var bulletLifeTimer = 0;
public function InfectedScripting():void {
iGun = new SCAR_GUN_mc;
addEventListener(MouseEvent.MOUSE_MOVE, mouseMove_handler);
addEventListener(MouseEvent.CLICK, doSlug);
this.addChild(iGun);
iGun.x = 250;
iGun.y = 200;
iGun.cacheAsBitmap = true;
}
private function mouseMove_handler(e:Event):void {
var theX:int = mouseX - iGun.x;
var theY:int = (mouseY - iGun.y) * -1;
var angle:Number = Math.atan(theY/theX)/(Math.PI/180);
if (theX<0) {
angle += 180;
}
if (theX>=0 && theY<0) {
angle += 360;
}
iGun.rotation = (angle*-1);
}
private function doSlug(e:Event){
if(reloadComplete == true){
var iBullet:MovieClip = new MovieClip();
iBullet = new iBullet_mc
iBullet.name = "slug" + bulnum
bulnum += 1 ;
addChild(iBullet)
setChildIndex(iBullet, 0);
iBullet.rotation = iGun.rotation
iBullet.x = spawnX;
iBullet.y = spawnY;
iBullet.bulletLifeTimer = 0;
randomNum = ((Math.random()* bulletOffset)-(bulletOffset/2));
var iBulletAngle = ((iGun.rotation+randomNum-90) * Math.PI/180);
iBullet.xSpeed = Math.cos(iBulletAngle)*iBulletSpeed;
iBullet.ySpeed = Math.sin(iBulletAngle)*iBulletSpeed;
iBullet.addEventListener("enterFrame", slugz_handler)
function slugz_handler(enterFrame:Event){
iBullet.x += iBullet.xSpeed;
iBullet.y += iBullet.ySpeed;
if (iBullet.bulletLifeTimer>=bulletLifeTimerTotal) {
//removeChild(this)
trace("REMOVE ME!")
}
iBullet.bulletLifeTimer += 1;
}
myTimer.addEventListener(TimerEvent.TIMER, myFunction);
startReloading();
}
}
private function myFunction(event:TimerEvent):void {
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, gunReloaded)
trace(myTimer.currentCount);
}
private function startReloading(){
reloadComplete = false;
myTimer.start();
}
private function gunReloaded(){
reloadComplete = true;
myTimer.reset();
}
}
}
And the error i get is one ive had before but dont fully understand so yea.
ArgumentError: Error #1063: Argument count mismatch on InfectedScripting/::gunReloaded(). Expected 0, got 1.
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.utils::Timer/flash.utils:Timer::tick()
thx guys