Yamiko
Yamiko

Reputation: 5453

as3 error 1063 with timer

getting error 1061: Call to a possibly undefined method stop through a reference with static type flash.events:TimerEvent. on my as3 class. I'm just starting to learn as3 and cant figure out whats causing the error. code:

package  {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;

public class game extends MovieClip
{
    //assign types to var names
    //allows values and variables to be acessed in methods
    public var as1:astroid;//astroids
    public var ship1:ship;//ship
    public var timer:Timer;

    public function game() 
    {
        //astroid
        as1=new astroid();
        addChild(as1);
        //ship
        ship1=new ship();
        addChild(ship1);
        //timer
        timer=new Timer(25);//every n frames
        timer.addEventListener( TimerEvent.TIMER, onTick );//attach function to timer
        timer.start();//start timer
    }
    public function onTick( timer:TimerEvent ):void 
    {
        //animate astroid
        as1.moveDown();
        //move ship
        ship1.x = mouseX;
        ship1.y = mouseY;

        if(ship1.hitTestObject(as1))
        {
            timer.stop();//error on this line!
        }
    }

}

}

Upvotes: 0

Views: 328

Answers (1)

laurent
laurent

Reputation: 90736

Rename timer to event in your event handler:

public function onTick( event:TimerEvent ):void 

Also, in Flash CS5, go to File > Publish Setting > Flash, and turn on "Permit debugging". That should give you more useful error messages.

Upvotes: 2

Related Questions