/ Published in: ActionScript
A CountEvent class’s instance counts up from 0 to 50, then dispatches "countComplete" event. Here’s a result below.
1
2
3
.
.
.
48
49
50
Count Complete
1
2
3
.
.
.
48
49
50
Count Complete
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// EventTest.as class EventTest extends MovieClip { var countEvent:MovieClip; public function EventTest() { countEvent = this.attachMovie( "countEvent", "countEvent", this.getNextHighestDepth() ); countEvent.addEventListener("countComplete", this.countComplete); countEvent.startCount(); } public function countComplete(event:Object):Void { trace("Count Complete"); } } //----------------- separated files ----------------- // CountEvent.as import mx.events.EventDispatcher; dynamic class CountEvent extends MovieClip { var counter:Number; var max:Number; public function CountEvent() { EventDispatcher.initialize(this); counter = 0; max = 50; } public function startCount():Void { this.onEnterFrame = function():Void { counter++; trace(counter); if(counter >= max) { delete this.onEnterFrame; this.dispatchEvent({type: "countComplete"}); } } } }