Ninja Warrior
Ninja Warrior

Reputation: 23

How to properly load multiple external swf files?

I'm creating an interactive game. I now have 6 swf files that I need to load and I need to play them sequentially.

I have a lots of question regarding this topic and here are they :)

1st Question: How can I load a external swf file after a cinematic scene?

In my 3rd swf files I have like a cinematic scene and it will be finished approximately 30 seconds. I know the delay method, but is it functioning smoothly when I already uploaded it to my website?

2nd Question: How to load all external files before user start playing the game?

How can I load all my swf files at once before letting the user play the game?

Here's some part sample of my code:

import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLRequest;

var myClip:MovieClip = root as MovieClip;
var externalClip:MovieClip;
var myLoader:Loader = new Loader();
var myLoader1:Loader = new Loader();

myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,       loaderCompletedHandler);


function loaderCompletedHandler(evt:Event):void {
externalClip = myLoader.content as MovieClip;
externalClip.ext_btn.addEventListener(MouseEvent.CLICK,extCommunicate);

  function extCommunicate(evt:MouseEvent):void {
    trace("TEST");
    myLoader1.contentLoaderInfo.addEventListener(Event.COMPLETE, thirdloaderCompletedHandler);
    var newstring:String = "third.swf";
    var newREQ:URLRequest = new URLRequest(newstring);
    addChild(myLoader1);
    myLoader1.load(newREQ);
    myLoader1.x=40;
    myLoader1.y=20;
    removeChild(myLoader);
  }
}

function thirdloaderCompletedHandler(evt:Event):void {
    trace("YEAH");
}

var externalString:String = "external.swf";
var urlREQ:URLRequest = new URLRequest(externalString);

playbtn.addEventListener(MouseEvent.CLICK,swfLoad);
function swfLoad(evt:MouseEvent):void {
    addChild(myLoader);
    myLoader.load(urlREQ);
    myLoader.x=40;
    myLoader.y=20;
}

3rd Question: Is the above code is the proper way of loading multiple swf files?

Upvotes: 2

Views: 779

Answers (1)

Many questions... (1) You can concatenate many swf files loading them by frame actions, not by AS3. This way you ensure the next movie will only be loaded when the previous got to its end. Or, in your terms, you only load the next movie after the first "cinematic" scene ends. Thus do not use "delays" because this will produce much different results according to the user configurations in terms of machine and bandwidth.

(2) You can preload all movies in a once the same way you would preload a single movie, it's just the case of writing the proper code, checking if movie1 was loaded, then movie2 and so on.

(3) Test your own code and verify is it works. If no, get the most you can about error messages and conditions and open another question here at StackOverflow exposing all the scenario, what you have, what you get and what you expect. Best

Upvotes: 3

Related Questions