package {
import flash.display.MovieClip;
import flash.events.*
public class Structure extends MovieClip {
public function Structure() {
PlusListeners()
}
public function PlusListeners() {
stage.addEventListener(Event.ENTER_FRAME, Event1);
stage.addEventListener(Event.ENTER_FRAME, Event2);
stage.addEventListener(Event.ENTER_FRAME, Event3);
stage.addEventListener(Event.ENTER_FRAME, Event4);
stage.addEventListener(Event.ENTER_FRAME, Event5);
stage.addEventListener(Event.ENTER_FRAME, Event6);
stage.addEventListener(Event.ENTER_FRAME, Event7);
stage.addEventListener(Event.ENTER_FRAME, Event8);
stage.addEventListener(Event.ENTER_FRAME, Event9);
stage.addEventListener(Event.ENTER_FRAME, Event10);
}
private function Event1(event:Event):void {
trace("This is event1")
}
private function Event2(event:Event):void {
trace("This is event2");
}
private function Event3(event:Event):void {
trace ("This is event3");
}
private function Event4(event:Event):void {
trace ("This is event4");
}
private function Event5(event:Event):void {
trace ("This is event5");
}
private function Event6(event:Event):void {
trace ("This is event6");
}
private function Event7(event:Event):void {
trace("This is event7");
}
private function Event8(event:Event):void {
trace ("This is event8");
}
private function Event9(event:Event):void {
trace ("This is event9");
}
private function Event10(event:Event):void {
trace ("This is event10");
}
}
}
Now, I had a few unique errors when creating this. This is the first error:
C:\Users\Owner\Documents\FlashCS5\Structure\Structure.as, Line 26 1046: Type was not found or was not a compile-time constant: Event.
After some trial and error I figured this one out. When flash compiled my SWF, it was looking for the Event constant and couldn't find it because I hadn't imported it. Now often times flash will import classes automatically as needed, but there is no guarantee. Eventually you're going to have to learn the classes so that you can import them when you need them.
import flash.events.*
The second error was a nail biter:
C:\Users\Owner\Documents\FlashCS5\Structure\Structure.as, Line 26 1126: Function does not have a body.
private function Event1(event:Event);{
trace("This is event1")
}
So why does Flash keep lying to me and saying that my function doesn't have a body when it does? Well, there's a semicolon at the end of the function when the compiler sees that semicolon, the function body becomes invisible.
this version works:
private function Event1(event:Event):void {
trace("This is event1")
}
No comments:
Post a Comment