Hi,
I have created a main movie which I would like to load 2 external swf's in succession.I would like that when the 1st swf is finished playing, it should be replaced by the second swf. I would also like that there be no blank screen in between the unloading of the 1st swf and loading up of the 2nd swf, if this is possible.
I have very little knowledge of AS, so I would appreciate that the person who responds to this question should be as explicit as possible.
Many thanks.
This is unrealistic to expect that someone will provide a complete implementation for this application. It is more efficient to split your questions into smaller problems you need to solve so you can gradually move from one step to another.
Show what you have done so far and where you got stuck.
Ok- this is the code that loads in the first swf, that I have on the first frame-
var my_Loader:Loader = new Loader();
addChild(my_Loader);
var my_url:URLRequest=new URLRequest("1-6.swf");
my_Loader.load(my_url);
I need to remove this swf after it has finished playing and replace it with another swf
How do I do this and how do I avoid creating a blank screen during this transition?
What constitutes loaded swf "finished playing"? If the loaded swf is a one timeline application and "finished playing" is when it gets to its last frame - you can add ENTER_FRAME event listener to it and when it gets to the last frame - get rid of it.
If the loaded swf is a more complex application or doesn't have a timeline - you will need to implement a mechanism INSIDE loaded swf that will notify that it finished playing. The best way would be to dispatch an event from it. In this case the main container will listen to this event at act upon receiving it.
As for the transition, you are dealing with Internet and, thus, with a lot of unpredictable latencies. Because of it if you need a smooth transition - the only way would be to preload next swf and display it when first one is finished playing.
Something like this:
var my_Loader:Loader = new Loader();
my_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
my_Loader.load(new URLRequest("1-6.swf"));
var currentSWF:MovieClip;
function onLoadComplete(e:Event):void {
my_Loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoadComplete);
currentSWF = MovieClip(e.target.loader.content);
currentSWF.addEventListener(Event.ENTER_FRAME, onEnterFrame);
addChild(currentSWF);
}
function onEnterFrame(e:Event):void
{
if (currentSWF.currentFrame == currentSWF.totalFrames) {
currentSWF.stop();
removeChild(currentSWF);
currentSWF.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
// if you want to get rid of it altogether
currentSWF = null;
my_Loader.unloadAndStop();
}
}
I managed to convert the swf's into AS3, but now I have encountered a different error message-
Scene 1, Layer 'first_half', Frame 1, Line 13 Warning: 1090: Migration issue: The onEnterFrame is not triggered automatically by Flash Player at run time in ActionScript 3.0. You must first register this handler for the event using addEventListener ( 'enterFrame', callback_handler).
I created a new loader instance, however the 2 swf's now play at the same time.
Here is my code-
var my_Loader:Loader = new Loader();
my_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
my_Loader.load(new URLRequest("sc_02_shyamal.swf"));
var currentSWF:MovieClip;
function onLoadComplete(e:Event):void {
my_Loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoadComplete);
currentSWF = MovieClip(e.target.loader.content);
currentSWF.addEventListener(Event.ENTER_FRAME, onEnterFrame);
addChild(currentSWF);
}
function onEnterFrame(e:Event):void
{
if (currentSWF.currentFrame == currentSWF.totalFrames) {
currentSWF.stop();
removeChild(currentSWF);
currentSWF.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
// if you want to get rid of it altogether
currentSWF = null;
my_Loader.unloadAndStop();
}
}
var my_Loader2:Loader = new Loader();
my_Loader2.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
my_Loader2.load(new URLRequest("sc_08_sujoy.swf"));
var currentSWF2:MovieClip;
function onLoadComplete2(e:Event):void {
my_Loader2.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoadComplete);
currentSWF = MovieClip(e.target.loader.content);
currentSWF.addEventListener(Event.ENTER_FRAME, onEnterFrame);
addChild(currentSWF);
}
function onEnterFrame2(e:Event):void
{
if (currentSWF2.currentFrame == currentSWF2.totalFrames) {
currentSWF2.stop();
removeChild(currentSWF);
currentSWF2.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
// if you want to get rid of it altogether
currentSWF2 = null;
my_Loader2.unloadAndStop();
}
}
Here is the folder that contains the project I am working on- http://dl.dropbox.com/u/8730678/loading_swf%27s.zip
North America
Europe, Middle East and Africa
Asia Pacific