|
-
Load External SWF using AS3
Ok I'm very, very new to this but this is what I wanted to happen
I made a series of individual animations that I now have to flow together. Since the animations are different flash files, I figured maybe I'll create a new Flash file and just load in all the individual swfs to just play continuously. NO mouse click needed. I just need it to play when opened and thats it.
So would a load movie be the way to go? If so I found this code
var request:URLRequest = new URLRequest("http://www.[yourdomain].com/externalSwf.swf");
var loader:Loader = new Loader()
loader.load(request);
addChild(loader);
AND
do external swfs have to be hosted on the web? can i just type out a path? If I can just include a patch what's the syntax for this?
Thanks!!!!
-
I would imagine that code would work. I haven't done any external loading w/ AS3 yet, but that looks right. One thing you'll have to make sure of if you're playing continuous animations is that they're all loaded before you start playing, otherwise you may run into one animation reaching its end before the next is loaded.
Also, yes, the main SWF needs access to external SWFs to load them. This happens at run-time, not compile-time, meaning if you go and upload the main SWF, it will need the other files hosted online as well (either locally on the same server or as an absolute path to a different server). If you go linking to your C: drive, it's not going to work for anyone but you.
-
Load External SWF using AS3
I've been able to externally Load the swf (yay!)'
BUT
I can only do it for 1 swf, I need to have 11 swfs autoplay.
how can I do this? The current swf needs to be removed and load in a new one. While the other swfs are being loaded it needs to be stopped so when it loads it starts from the top! I would also need a slight alpha transition when a new swf starts.
I know, I know a lot of requests.... help?
This is the code I ended up with to load 1 external swf:
var img1Request:URLRequest=new URLRequest("swfs/ADVAllDemoFLASHv1.0.swf");
var img1Loader:Loader = new Loader();
img1Loader.load(img1Request);
_1.addChild(img1Loader);
so how will this work for 11 others?
thanks!
-
Well, first things first. To get ALL the files loaded, you'd set up an array and loop through everything to get it all loading. Then you'd need to set up a trigger so when it's finished loading, it can keep track of it. We can just use a single integer and then once it's equal to the length of the array, we're done loading everything. From there, we can start playing the animations.
(Note this code is completely untested and very likely contains all sorts of errors.)
Code:
var externalSWFs:Array = new Array(
"swfs/ADVAllDemoFLASHv1.0.swf",
"swfs/File2.swf",
"swfs/File3.swf"
// etc
);
var loadedSWFs:Array = new Array();
for (var i:int=0; i<externalSWFs.length; i++)
{
// create a loader
var imgLoader:Loader = new Loader();
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
// load the SWF
var imgRequest:URLRequest = new URLRequest(externalSWFs[i]);
imgLoader.load(imgRequest);
// keep track of the SWF for later
loadedSWFs.push(imgLoader);
addChild(imgLoader);
}
var loaded:int = 0;
var currentAnimation:int = 0;
function loadComplete(event:Event):void
{
// pause and hide the SWF
event.target.loader.stop();
event.target.loader.visible = false;
if (++loaded == externalSWFs.length)
{
// all SWFs loaded
// start the first animation
loadedSWFs[currentAnimation].visible = true;
loadedSWFs[currentAnimation].play();
currentAnimation++;
}
}
This code should theoretically load everything and then play the first animation. The next step then is to start the next animation once the first is finished, and so on. And of course, alpha blending, like you mentioned. But let's make sure you can get the first animation playing first.
-
Load External SWF using AS3
ah, I get what you're saying.
So... I keep getting this error?
ReferenceError: Error #1069: Property Loader not found on flash.display.LoaderInfo and there is no default value.
at test1_fla::MainTimeline/loadComplete()
also, Only the 3rd swf plays, it's always the last swf that plays.
--------
THIS WAS THE CODE:
import flash.display.*;
import flash.net.URLRequest;
var externalSWFs:Array = new Array(
"swfs/ADVRulesMgrFLASHv1.0.swf", "swfs/ADVGenevaFLASHV2.2.swf", "swfs/ADVIndAdvisorFLASHv1.0.swf");
var loadedSWFs:Array = new Array();
for (var i:int=0; i<externalSWFs.length; i++) {
// create a loader
var imgLoader:Loader = new Loader();
imgLoader.contentLoaderInfo.addEventListener(Event .COMPLETE, loadComplete);
// load the SWF
var imgRequest:URLRequest=new URLRequest(externalSWFs[i]);
imgLoader.load(imgRequest);
// keep track of the SWF for later
loadedSWFs.push(imgLoader);
_1.addChild(imgLoader);
}
var loaded:int=0;
var currentAnimation:int=0;
function loadComplete(event:Event):void {
// pause and hide the SWF
event.target.Loader.stop();
event.target.Loader.visible=false;
if (++loaded==externalSWFs.length) {
// all SWFs loaded
// start the first animation
loadedSWFs[currentAnimation].visible=true;
loadedSWFs[currentAnimation].play();
currentAnimation++;
}
}
Thank you so much for helping me!!!
-
Oh sorry about that error... typo on my part. You need lowercase "loader".
Code:
event.target.loader.stop();
event.target.loader.visible=false;
That's strange that it's playing the final SWF first. I don't see any error in my code (although maybe I'm blind, who knows). I'd muck around in the debugger to figure out what's going on, if I were you.
[edit]
Actually now that I'm looking at this again, it may be because of the typo I mentioned. Fix that and see if it fixes the final one playing.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|