Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
The external SWF does have a timeline and I would like that it should disappear when it reaches the last frame of its timeline. Could you give me the exact code for this event listener and instructions on where to put it?
Copy link to clipboard
Copied
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();
}
}
Copy link to clipboard
Copied
Thanks for the code, however I am getting the following error message-
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::AVM1Movie@218db341 to flash.display.MovieClip.
at complete_loader_fla::MainTimeline/onLoadComplete()
Copy link to clipboard
Copied
Oh, your external swfs are written in AS2.
AS2 and AS3 are totally incompatible. Do you have control of external swfs?
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
This is not an error but warning that doesn't affect anything. I suggest you turn off the warnings.
Copy link to clipboard
Copied
Ok- and how do I load in the second SWF?
Copy link to clipboard
Copied
The same way you load the first one. You can create another Loader instance or an Array that will holds loaders or their content.
Copy link to clipboard
Copied
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