Jump to content
GreenSock

UbiAssassin

[Solved]Class file plays too quickly.

Recommended Posts

This is probably a ridiculous question, but I assumed that the class for my Main.swf would not start running until the Main.swf was actually told to play. I am loading the main.swf in my preloader.swf, but I am setting it to autoPlay: false. During my cleanup phase in the preloader class, the main class is starting to play before I tell the Main.swf to play.

 

Do I need to do something extra to halt the class file's progress? I thought that it would not activate until its parent movie was actually set to play.

 

Here is the cleanup section of my preloader:

 

	private function completeHandler(event:LoaderEvent):void
	{
		trace(event.target + " complete");
		removeEventListener(LoaderEvent.PROGRESS, progressHandler);
		removeEventListener(LoaderEvent.COMPLETE, completeHandler);
		TweenMax.delayedCall(1, cleanPreloaderA);
	}

	private function cleanPreloaderA():void
	{
		removeChildAt(0);
		removeChildAt(1);
		TweenMax.delayedCall(0.1, cleanPreloaderB);

	}

	private function cleanPreloaderB():void
	{
		trace("Cleanup Preloader");
		removeChildAt(0);
		removeChildAt(1);
		TweenMax.delayedCall(0.1, runMainSite);

	}

	private function runMainSite():void
	{
		trace("Run Main Site");
		removeChildAt(0);
		LoaderMax.getLoader("mainSite").rawContent.play();
	}

}
}

 

I have several functions that clean up various parts of the preloader setup, and the very last function activates my mainsite.swf. The problem that I am having is that the class for the mainsite.swf is starting during the end of the preloader class instead of after the completion of the "runMainSite" function, which I did not think was possible. I am guessing this is happening because the mainsite is loaded therefore its class is loaded and setting the swf to autoPlay: false does not stop the class file from proceeding?

 

Thanks :)

Link to comment
Share on other sites

is the trace("run main site") happening at the expected time?

 

what code do you have in the document class for the swf that gets loaded by "mainSite" ?

 

its hard to trouble shoot without seeing that code.

 

keep in mind autoPlay:false only prevents the loaded swf's timeline from advancing, it doesn't prevent code from executing.

 

maybe that helps.

Link to comment
Share on other sites

keep in mind autoPlay:false only prevents the loaded swf's timeline from advancing, it doesn't prevent code from executing.

 

 

Yes, thank you, that helped :) Sadly I cannot seem to find a way that does not error-out to pause the Class and only allow it to run when the mainSite.swf is actually called to play.

 

If I put things in the MainClass to stop its progress, then it just errors out or halts the progress forever. I am not sure how to send a signal from the preloader class that it can access in the MainClass>.< Everything I have tried thus far has not worked. Is there a way to update a variable from one Class to another?

 

Do you have a code example of a fake event to fire in the end of the preloader class that I could listen for in the main class? I was thinking that if I could create some fake event in the final function of my preloader class then my main class could just wait for that event before it progresses. I have not really been able to get it working yet though.

 

Thanks!

 

Ok, so I tried using LocalConnection to create the communication I needed. I get this error(Error #2044: Unhandled StatusEvent:. level=error, code=).

 

Here is my preloader code:

 

package
{
import com.greensock.core.TweenCore;
import flash.display.*;
import flash.events.*;
import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import com.greensock.easing.*;
import flash.display.MovieClip;
import flash.net.LocalConnection;
import flash.text.TextField;

public class Levelforge_Preloader extends MovieClip
{

	private var connToMain:LocalConnection;

	//===============================================================
	//***Create Content Loaders, and LoaderMax Queue***
	//===============================================================

	private var navSwish:MP3Loader = new MP3Loader("http://levelforge.com/MP3/vwoom-Public_D-148.mp3", {name: "navSwishSound", rawProgress: 1, autoPlay: false, autoDispose: true, onProgress: progressHandler, onComplete: loaderHandler, estimatedBytes: 55296});
	private var navRollOver:MP3Loader = new MP3Loader("http://levelforge.com/MP3/ayuigo-xrikazen-80.mp3", {name: "navOverSound", rawProgress: 1, autoDispose: true, autoPlay: false, onProgress: progressHandler, onComplete: loaderHandler, estimatedBytes: 33792});
	private var navButtonClick:MP3Loader = new MP3Loader("http://levelforge.com/MP3/button-11.mp3", {name: "navClickSound", rawProgress: 1, autoDispose: true, autoPlay: false, onProgress: progressHandler, onComplete: loaderHandler, estimatedBytes: 7168});
	private var song1:MP3Loader = new MP3Loader("http://levelforge.com/08 Hunted (Instrumental).mp3", {name: "Hunted", rawProgress: 1, autoDispose: true, autoPlay: false, volume: .35, onProgress: progressHandler, onComplete: loaderHandler, estimatedBytes: 6617088});
	private var song2:MP3Loader = new MP3Loader("http://levelforge.com/WITHOUT INST.mp3", {name: "Without", rawProgress: 1, autoDispose: true, autoPlay: false, volume: .35, onProgress: progressHandler, onComplete: loaderHandler, estimatedBytes: 2148352});
	private var levelforgeMainSwf:SWFLoader = new SWFLoader("http://levelforge.com/WebsiteFlash10/Levelforge_NewAS3.swf", {name: "mainSite", rawProgress: 1, autoPlay: false, width: 1024, height: 768, scaleMode: "none", onProgress: progressHandler, onComplete: loaderHandler, estimatedBytes: 574464});
	private var queue:LoaderMax = new LoaderMax({name: "mainQueue", rawProgress: 1, onProgress: progressHandler, onComplete: completeHandler});

	public function Levelforge_Preloader()
	{
		var preloader:SelfLoader = new SelfLoader(this, {name: "self", rawProgress: 1, onProgress: progressHandler, onComplete: loaderHandler, estimatedBytes: 23552});

		//========================================================================
		//***Set up what needs to be Loaded and Load it. Add Event Listeners.***
		//========================================================================

		LoaderMax.defaultAuditSize = false;
		queue.append(preloader);
		queue.append(navSwish);
		queue.append(navRollOver);
		queue.append(navButtonClick);
		queue.append(song1);
		queue.append(song2);
		queue.append(levelforgeMainSwf);
		queue.load();
		queue.addEventListener(LoaderEvent.COMPLETE, completeHandler);
		queue.addEventListener(LoaderEvent.PROGRESS, progressHandler);
	}

	//======================================================================================================
	//***Functions that Handle Progress and Completion. They also control the Movie Progression Updates.***
	//======================================================================================================

	private function progressHandler(event:LoaderEvent):void
	{
		//trace("Watching Progress Now");
		var percent:Number = event.target.bytesLoaded / event.target.bytesTotal;
		var circleLoaderProgress:Number = Math.round((event.target.bytesLoaded / event.target.bytesTotal) * 100);
		myLoadText.text = Math.round(percent * 100) + "%".toString();
		circleLoader.gotoAndStop(circleLoaderProgress);
	}

	private function loaderHandler(event:LoaderEvent):void
	{
		trace(event.target + " complete");
	}

	private function completeHandler(event:LoaderEvent):void
	{
		trace(event.target + " complete");
		TweenMax.to(this, 1, {autoAlpha: 0, ease: Quad.easeIn});
		removeEventListener(LoaderEvent.PROGRESS, progressHandler);
		removeEventListener(LoaderEvent.COMPLETE, completeHandler);
		TweenMax.delayedCall(0, runMainSite);
		TweenMax.delayedCall(0, sending);
	}

	private function runMainSite():void
	{
		trace("Run Main Site");
		LoaderMax.getLoader("mainSite").rawContent.play();
		LoaderMax.getLoader("mainSite").dispose(false);
	}

	public function sending():void {
		trace("Sending Message");
		connToMain = new LocalConnection();
		connToMain.send("beginMainClass", "waitOnPreloader");
	}

}
}

 

The error is thrown right after the trace "Sending Message." Here is the receiver code and method in my MainClass:

 

		connToMain = new LocalConnection();
		connToMain.connect("beginMainClass");

//later in the code is the function:

	private function waitOnPreloader():void
	{
		trace("Connection Message Received");
		TweenMax.delayedCall(.5, initButtonSounds);
	}

 

Hopefully that makes sense.

Link to comment
Share on other sites

Voila! I found a great way to get around my issue!

 

There is an awesome little library called TimeLineWatcher http://www.adobe.com/devnet/flash/articles/timelinewatcher.html. I just added a label to the correct place on the Main movie's timeline. My main movie class just sits waiting on an eventlistener for that label to be reached. Problem solved :D Maybe someone else can solve something with this as well.

 

Thanks everyone :)

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.
×