Hello,
I’m not exactly a Flash Professional, but I’m hoping most of you are. I’ve chosen to do a site in AS3 because I like Tween Class. I’ve run into a serious snag though. Preloaders and loadMovie. I’ve searched and searched google and I’ve gotten nothing but extremely vague results.
I have a main movie that I would like to preload. This movie will load one additional movie on top of it (nothing complex). But in AS3, it seems to be a chore.
Do any of you knowledgeable folks at ultrashock have a step by step tutorial or even willing to post the steps/code here?
I appreciate any information you have to offer. Remember, try to respond to this thread in the most basic of terms. I am not a coder, but I’m trying.
Thanks,
Cmoore
Hi cmoore, welcome to Ultrashock. ![]()
The Loader class is what you need to be looking at really. It is the main class you will use to load external SWF and image files.
It is difficult to tell how much of this you have already picked up but here is a quick example of how to load an external SWF file and listen for progress/complete events.
[as]// A URLRequest object pointing to the external movie.
var mainURL:URLRequest = new URLRequest( “movie.swf” );
// A Loader object (use to load SWF, PNG, GIF, JPG).
var mainMovie:Loader = new Loader();
// Add listeners to the Loader.contentLoaderInfo object.
mainMovie.contentLoaderInfo.addEventListener( ProgressEvent.PROGRESS, progressListener );
mainMovie.contentLoaderInfo.addEventListener( Event.COMPLETE, completeListener );
// Load the external movie using the URLRequest.
mainMovie.load( mainURL );
// Invoked while the exteral movie is loading.
function progressListener( event:ProgressEvent ):void
{
trace( “progress = ” + event.bytesLoaded );
// This is where you would update the progress bar.
}
// Invoked when the external movie has completed loading.
function completeListener( event:Event ):void
{
trace( “complete” );
addChild( mainMovie );
// It would be a good idea to remove the
// mainMovie.contentLoaderInfo listeners here as well.
}[/as]
If you need any more help feel free to ask.
- 21 August 2007 01:35 AM
-
Author
Thank you so much for your help. I used the code and it works. The only thing that really confused me is where you said…
// This is where you would update the progress bar.
The way I used to do it was with a dynamic text field. Is this what you mean? Do you mean using a progress bar component? If you meant the text field, what would I call it?
Thank you again. I really appreciate it.
Cmoore
- 21 August 2007 02:26 AM
-
Originally posted by cmoore
...
Do you mean using a progress bar component? If you meant the text field, what would I call it?
...
It depends on what you want to do really. I added that comment into the progressListener() function because that is where you can grab the number of bytes loaded and do the percentage calculations etc, so it would be the easiest place to update your progress bar or text field.
[as]function progressListener( event:ProgressEvent ):void
{
trace( “progress = ” + event.bytesLoaded );
var percent:int = 0;
if( event.bytesTotal > 0 && event.bytesLoaded > 0 )
{
percent = (100 / event.bytesTotal) * event.bytesLoaded;
}
myTextField.text = percent + “%”;
}[/as]
- 21 August 2007 02:36 AM
-
Author
Worked great. Thanks for your time. Just curious, but are load levels now obsolete? If not, how are they determined? Is it by the order they are loaded? I’m just curious, because I might be loading a second swf into this mainmovie.
Take care and thanks again Nutrox.
Cmoore
- 21 August 2007 03:09 AM
-
@cmoore
Levels no longer exist in AS3, instead everything is displayed and arranged in display lists. You should take a look at the DisplayObjectContainer class (or the Sprite or MovieClip class) because it contains the functions you will need such as addChild() removeChild() getChildIndex() swapChildren() and so on.
@geo_speed
You need to access the loaded SWF file via the Loader.content property, so once the external SWF file has loaded you could then do something like this:
[as]MovieClip(myLoader.content).gotoAndStop( 10 );[/as]
Where myLoader is your Loader object.
- 21 August 2007 04:47 AM
-
Thanks Nutrox, But it’s not working.
[AS] function completeListener( event:Event ):void
{
trace( “complete” );
// trace(mainMovie);
addChild(mainMovie);
MovieClip(mainMovie.content).gotoAndStop( 100 );
// me add the line here
// It would be a good idea to remove the
// mainMovie.contentLoaderInfo listeners here as well.
}[/AS]
I used your code only.
- 21 August 2007 05:46 AM
-
- Log in or join for free to make a comment.


