0

I have numerous large swfs that I am placing into a main swf using different buttons. I am experiencing quite a delay when the external swfs are called to load and play (because of their size). (Note: I do not experience any delay in loading the external swfs when playing the main swf locally, however when burned to a CD, the large external swfs load very slowly into the main swf each time their button is clicked.) The code I use to load the swfs:

var Lesson1_Loader:Loader;
Lesson1_Loader = new Loader();

Lesson1Numberbtn.addEventListener(MouseEvent.CLICK, playL1);
function playL1(e:Event):void
{
Lesson1_Loader.load(new URLRequest("Lesson1.swf"));
addChild(Lesson1_Loader);
 }

My question: Is there a way to have the external swfs start loading themselves (but not playing) when the main swf is opened (there is an introductory animation in the main swf before any external swfs are played), so that when I click each button and addChild for each external swf, it is already loaded and will play instantly without delay?

Thank you in advance!

Update: I am using timeline code (I know not preferred). I've tried to this version:

var Lesson1_Loader:Loader;
Lesson1_Loader = new Loader();
Lesson1_Loader.load(new URLRequest("Lesson1.swf"));

Lesson1Numberbtn.addEventListener(MouseEvent.CLICK, playL1);
function playL1(e:Event):void
{
addChild(Lesson1_Loader);
 }

...however then Lesson1.swf seems to play (behind the scenes) automatically at the start of main.swf (I know this because Lesson1.swf has sound on frame 1 and I hear it, however Lesson1.swf visually does not show up until I click the 'Lesson1Numberbtn' button and addChild. Lesson1.swf itself does not have "stop();" on Frame 1, so that it plays automatically when loaded. I could add stop(); to frame 1 of Lesson1.swf, but then how do I start Lesson1.swf to play from the main.swf once I addChild?

Update Again: I have tried this code to control the playing and stopping of Lesson1.swf, but it does not work:

Lesson1_Loader.load(new URLRequest("Lesson1.swf"));
Lesson1_Loader.contentLoaderInfo.addEventListener(Event.INIT, NotYetL1 );

function NotYetL1(initEvent:Event ):void{
MovieClip(initEvent.currentTarget.content).stop();
}
Shana B
  • 1
  • 2
  • Should be simple enough. Are you using classes or using timeline code? Either way, you would need to find a way to execute the loading code (inside your current method `playL1`) at the start of main.swf and not inside the click event handler of the button. – Gurtej Singh Nov 08 '18 at 22:45
  • @Gurtej Singh please see update above. (The comment section said it was too many words for a comment.) – Shana B Nov 09 '18 at 00:34
  • No worries! I found another thread that will help you as to how to stop and play the SWF based on your needs. Have a look here: https://stackoverflow.com/questions/2365695/as3-stop-external-swf – Gurtej Singh Nov 09 '18 at 00:44
  • I tried this but it does not stop Lesson1.swf from playing: – Shana B Nov 09 '18 at 01:00
  • Lesson1_Loader.load(new URLRequest("Lesson1.swf")); Lesson1_Loader.contentLoaderInfo.addEventListener(Event.INIT, NotYetL1 ); function NotYetL1(initEvent:Event ):void{ MovieClip(initEvent.currentTarget.content).stop(); } – Shana B Nov 09 '18 at 01:00
  • That's probably because you are adding the event listener after your `.load` method. Can you call `load` after this line: `Lesson1_Loader.contentLoaderInfo.addEventListener(Event.INIT, NotYetL1 );` – Gurtej Singh Nov 09 '18 at 02:28
  • Ok did that, but unfortunately it is still not working. – Shana B Nov 09 '18 at 02:54
  • Can you try EVENT.COMPLETE? – Gurtej Singh Nov 09 '18 at 03:53
  • Just tried. Also does not work. Lesson1.swf still plays automatically. – Shana B Nov 09 '18 at 04:27

0 Answers0