PDA

View Full Version : Noob ENTER_FRAME Question


elveatles
06-15-2008, 09:22 PM
Hi, I've just started learning AS3 so I bought the book "Learning ActionScript 3.0". I copies one of the examples exactly as it was written in the book, yet I got the error: "1046: Type was not found or was not a compile-time constant: Event."

Here's the code (it tells me the error is on the line that says
"public function onLoop(evt:Event):void":

package
{
import flash.display.MovieClip;
import flash.display.Graphics;
import flash.display.Event;

public class Box extends MovieClip
{
public var color:uint = 0x000099;

public function Box()
{
//draw a shape at runtime
this.graphics.lineStyle(1, 0x000000);
this.graphics.beginFill(color);
this.graphics.drawRect(0, 0, 100, 100);
this.graphics.endFill();

this.addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);
}

public function onLoop(evt:Event):void //Error line
{
this.x += 5;
}
}
}

Makes no sense to me why it refuses to work.

doemsche
06-15-2008, 09:38 PM
you use the wrong import statement

import flash.display.MovieClip;
import flash.display.Graphics;
import flash.events.Event; //not flash.display.Event!

fl.barrett
06-15-2008, 09:38 PM
You are getting the error because Event ain't situated in the flash.display package but in the flash.events package. Replace: import flash.display.Event; with import flash.events.Event; and it should work just fine.

elveatles
06-16-2008, 12:10 AM
Lol, thank you. That was silly of me.