0

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?

avanderw
  • 675
  • 1
  • 7
  • 22
  • Have you tried with Sprite and not succeeded? – inhan Oct 05 '12 at 08:00
  • To be honest, I have no project setup right now for it and am a bit too lazy to boot up my flash environment. Quickly busy with some Java stuff first. – avanderw Oct 05 '12 at 08:06
  • Downvote for laziness, upvote for honesty. And short answer; it can (and should) extend Sprite unless you use the timeline (in which case it has to use MovieClip). – Jonatan Hedborg Oct 06 '12 at 23:38

3 Answers3

3

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.

Vesper
  • 18,599
  • 6
  • 39
  • 61
0

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.

avanderw
  • 675
  • 1
  • 7
  • 22
0

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.

iND
  • 2,663
  • 1
  • 16
  • 36