Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
jguthrie

Loading appears to happen twice in preloader?

Recommended Posts

It seems that when my preloader loads the main swf, it loads it twice. The textfield that is used to report the progress starts at a random percentage, then goes up to 99, then resets to 0 and goes back up...

 

Any ideas on why this would occur? I was wondering if the initial call that LoaderMax makes to determine the size would cause this...

package {

import com.greensock.TimelineLite;
import com.greensock.TweenLite;
import com.greensock.easing.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.SWFLoader;

import flash.display.DisplayObjectContainer;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;
import flash.events.SecurityErrorEvent;
import flash.events.StatusEvent;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.system.Security;
import flash.text.TextField;
import flash.utils.getTimer;
import flash.external.ExternalInterface;

public class ChristmasPreLoader extends MovieClip {

	//public var _queue:LoaderMax;
	private var _swfLoader:SWFLoader;

	//public var _sSponsorButton:SimpleButton;
	public var _sSponsorText:TextField;
	public var _sLoading_txt:TextField;
	public var _sPattern_mc:MovieClip;
	public var _sStitches:MovieClip;
	public var _sDrop_mc:MovieClip;
	public var _sBrownBucket:MovieClip;
	public var _sMaskBucket:MovieClip;

	private var _preLoaderTL:TimelineLite = new TimelineLite();
	private var _bucketTL:TimelineLite = new TimelineLite();

	public function ChristmasPreLoader():void {
		addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true); 
		//init();
	}

	private function init(e:Event):void {

		stage.showDefaultContextMenu = false;
		stage.scaleMode = StageScaleMode.NO_SCALE;
		stage.align = StageAlign.TOP_LEFT;	
		//, estimatedBytes:900200
		_swfLoader = new SWFLoader( "ChristmasCampaignVideo.swf", {container:this, alpha:0, onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});

		_preLoaderTL.append(TweenLite.to(_sDrop_mc, 1, {y: 370, ease:Expo.easeIn}));
		_preLoaderTL.append(TweenLite.to(_sDrop_mc, .01, {y: -70, onComplete:dropWater }));

		_bucketTL.append(TweenLite.to(_sPattern_mc, 1, {rotation: 15}));
		_bucketTL.append(TweenLite.to(_sPattern_mc, 1, {rotation: -15}));
		_bucketTL.append(TweenLite.to(_sPattern_mc, .5, {rotation: 0, onComplete:rotateBucket}));

		_swfLoader.load();

		//_sSponsorButton.addEventListener(MouseEvent.CLICK, sponsorClick, false, 0, true);
		removeEventListener(Event.ADDED_TO_STAGE, init);
	}

	private function rotateBucket():void {
		_bucketTL.restart();
	}

	private function dropWater():void {
		_preLoaderTL.restart();
	}

	protected function errorHandler(event:Event):void {
		trace("ChristmasPreLoader SWFLoader.errorHandler");
	} 

	private function progressHandler(e:LoaderEvent):void {

		var perc:Number = e.target.progress;
		//trace("progress: " + e.target.progress);
		_sLoading_txt.text = 'Loading ' + Math.ceil(perc*100).toString() + '%';

		_sPattern_mc.y = 466 - (80 * perc);
	}

	private function completeHandler(event:LoaderEvent):void {		
		_preLoaderTL.stop();

		_sLoading_txt.text = "Loaded!";

		//TweenLite.to(_sSponsorButton, 1,{alpha:0});
		TweenLite.to(_sSponsorText, 1,{alpha:0});
		TweenLite.to(_sPattern_mc, 1,{alpha:0});
		TweenLite.to(_sStitches, 1,{alpha:0});
		TweenLite.to(_sDrop_mc, 1,{alpha:0});
		TweenLite.to(_sLoading_txt, 1,{alpha:0});
		TweenLite.to(_sBrownBucket, 1,{alpha:0, onComplete: cleanUp});
	}
	/*
	protected function sponsorClick(event:MouseEvent):void {
		try {
			ExternalInterface.call("OpenSponWindow","_preloader");
		} catch (e:Error) {
			trace('ChristmasPreLoader.sponsorClick error ' + e);
		}
	}
	*/
	private function cleanUp():void {
		//Cleanup		

		//removeChild(_sSponsorButton);
		//_sSponsorButton = null;

		removeChild(_sSponsorText);
		_sSponsorText = null;

		removeChild(_sPattern_mc);
		_sPattern_mc = null;

		removeChild(_sStitches);
		_sStitches = null;

		removeChild(_sDrop_mc);
		_sDrop_mc = null;

		removeChild(_sLoading_txt);
		_sLoading_txt = null;

		removeChild(_sMaskBucket);
		_sMaskBucket = null;

		removeChild(_sBrownBucket);
		_sBrownBucket = null;
		//Fade in main swf
		TweenLite.to(_swfLoader.content, 1, {alpha:1, onComplete: callOnComplete});
	}

	private function callOnComplete():void {
		//_swfLoader.rawContent.animatePlayButtonIn(null);
		try {
			ExternalInterface.call("removeSponsorButton");
		} catch (e:Error) {
			trace('ChristmasPreLoader.sponsorClick error ' + e);
		}
	}

	private function onLocalConnectionStatus(event:StatusEvent):void {
		switch (event.level) {
			case "status":
				trace("SiteLoadingTimeTracking - LocalConnection.send() succeeded");
				break;
			case "error":
				trace("SiteLoadingTimeTracking - LocalConnection.send() failed");
				break;
		}
	}
}
}

Link to comment
Share on other sites

The reason I see the progress bar go up twice is:

 

PreloaderSwf (using LoaderMax) loads in MainSwf which in turn loads a video (using LoaderMax).

 

I had requireWithRoot set to true for the video. So what I was seeing was the loadermax class in the preloader swf, loading the Main swf, and then the video.

Link to comment
Share on other sites

Yep, bingo. By the way, if you want to avoid that backwards jump, you can set the estimatedBytes on your SWFLoader to include the swf AND the video. Just an option.

Link to comment
Share on other sites

I actually dont mind it in that I 'know' when the main.swf has finished loading and when loading the video has started.

 

Except I am finding out in an odd way. Since preloader.swf is using loadermax to only load in main.swf, I 'discover' when main.swf has loaded when a netstatus event of the video fires "NetStream.Play.Start" ...

 

It may be handy to have the preloader load the main.swf and the video but the video needs to play 'within' main.swf and I wasnt sure how to hand off the video loader to main.swf...

 

Any ideas for that?

Link to comment
Share on other sites

I'm not quite sure what you mean by "hand off", but you can get the video from within the main.swf using the static LoaderMax.getLoader() method. Or pass the VideoLoader instance to a method in the main.swf. Lots of options actually.

Link to comment
Share on other sites

Ya that's what I meant. As in the best way to preload the vid & main.swf in the preloader.swf but have the video play from within the main.swf. Could also target a movieclip in the main.swf by using the container param in vidloader.

 

thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×