Avg. Rating 5.0

Problem

When using the Embed tag, [Embed(source="stuff.swf", symbol="a_mc")], it loads all embedded content in the first frame, even before my stage color loads. This renders my pre-loader useless. I make casual games and many game sites want all assets in one swf file, so I can't use a separate swf as a pre-loader. I have gone into Publish settings and set "Export classes in frame" to 3 and that didn't prevent all the content from loading in the first frame.

Solution

Create a listener to make sure that the movie has loaded, this is in AS2 (assumption because the question called for "a_mc" in the request). In AS3, this can be solved by creating your preloader then calling a function that adds the movie to the stage.

Detailed explanation

 //create listener for Movie being loaded
listener.onLoadProgress = function(target:MovieClip,
bytesLoaded:Number, bytesTotal:Number):Void {
    trace(target + ".onLoadProgress with " + bytesLoaded + " bytes
of " + bytesTotal);
 if (bytesLoaded == bytesTotal){
 }
}
listener.onLoadInit = function(target:MovieClip):Void {
    trace(target + ".onLoadInit");
 init(); //Whatever your first function is called.
}
mcLoader.addListener(listener);
mcLoader.loadClip("stuff.swf", a_mc);
 
This should prevent your movie to load before all the stage loads with AS2.
 
In AS3, this can be solved by creating your preloader then calling a function that adds the movie to the stage by using flash URLRequest and Loader class.
 
//import all the essentials
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
//run the initial function

init();

function init()
{
 //create a new loader
 var mcLoader:Loader = new Loader();
 //This is where you determine which file gets loaded
 var mClip:URLRequest = new URLRequest("stuff.swf");
 //adding Listeners
 mcLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
onComplete);
 mcLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,
onProgress);
 //Call the clip
 mcLoader.load(mClip);
}

function onProgress(mBytes:ProgressEvent)
{
 //check percentage of load progress
 var percent:Number = mBytes.bytesLoaded/mBytes.bytesTotal;
 trace("Percent Loaded: " + percent);
}

function onComplete(e:Event)
{
 //add swf to the stage
 addChild(e.currentTarget.content);
}


  
 
 

 


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes