Reputation: 675
Does the actionscript preloader have to extend MovieClip?
...
public class Preloader extends MovieClip
{
public function Preloader()
{
if (stage) {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
}
addEventListener(Event.ENTER_FRAME, checkFrame);
loaderInfo.addEventListener(ProgressEvent.PROGRESS, progress);
loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
// TODO show loader
}
...
Or can it also extend Sprite?
Upvotes: 0
Views: 241
Reputation: 2649
Yes, you can extend Sprite
.
Instead of frame events, you would use a TimerEvent
and a Timer
. If you wanted to avoid all frame- or time-based references for some reason, you could listen to the ProgressEvent
. You would create/load and manipulate the "preloader" graphics in either event's handler.
This is more difficult than is usually necessary, and much of duplicates MovieClip
functionality, so you would probably need a pretty good reason to go this route.
Upvotes: 0
Reputation: 675
After Vesper's answer. I did some fiddling
private function checkFrame(e:Event):void
{
if (currentFrame == totalFrames)
{
stop();
loadingFinished();
}
}
Sprite does not have access to currentFrame, totalFrames, or even the stop method. However, MovieClip does.
Upvotes: 0
Reputation: 18757
A preloader can only extend Sprite if it's actually loading a separate SWF. If you make an SWF with a built-in preloader, you need two frames, because Flash player loads frames sequentially, so it's the only way you can load and display a part of your SWF, which is required for a preloader to work. And for those frames you need a MovieClip, Sprites don't have frames.
Upvotes: 3