
Copy link to clipboard
Copied
ok, this is a tough one for me.....
ive figured out timeline transitions, and timeline based preloaders......so now i have a problem.....
i have my MAIN swf file that i load all my pages in externally ( external swf files )....
when i click a button ( for example ) my "about us" button - the transition begins....
i have a keyframe with the following code on frame 40 ( inside a movie clip named "pages" in my main SWF where all the buttons/transitions are 😞
var Xpos:Number=0;
var Ypos:Number=0;
var swf:MovieClip;
var bgloader:Loader = new Loader();
var bgURL
if(page==1){
bgURL=new URLRequest("pages/home.swf");
}
if(page==2){
bgURL=new URLRequest("pages/about.swf");
}
if(page==3){
bgURL=new URLRequest("pages/updates.swf");
}
if(page==4){
bgURL=new URLRequest("pages/contact.swf");
}
bgloader.load(bgURL);
bgloader.x=Xpos;
bgloader.y=Ypos;
bg.addChild(bgloader);
stop();
now as you can see, at the end it stops...and this is because my external swf files have timeline preloaders in them.....
now on frame 41 of my main swf, i created a label called "start" which i need to target from my external pages....
////////////////////////////////////////////
on all my external swfs i have this code on frame 2( and this is where i am having the problem 😞
if(framesLoaded==80){
MovieClip(parent).gotoAndPlay("start");
}
else if(framesLoaded<80){
gotoAndPlay(1);
}
now, where i have MovieClip(parent).gotoAndPlay("start"); - i am trying to target my MAIN swf files timeline ( which is inside a movie clip on the main timeline called "pages").
however, it doesnt work....i cannot get my external swf to communicate correctly for some reason.....
how do i code my external swf files to know that once frame 80 has loaded on them, that it needs to direct my MAIN swf file to gotoAndPlay("start"); ??
im hoping someone can help here....
1 Correct answer
You may not need all of what you're trying to accomplish if you are just waiting for the swf to load before you command the main timeline to move along. If you assign a listener to the loader you can determine when the file is loaded and ready to run without having the file figure that out itself and tell you about it. Just add an INIT listener to your loader...
bgloader.contentLoaderInfo.addEventListener(Event.INIT, eventHandler);
That line of code will have your main timeline waiting to call
...Copy link to clipboard
Copied
What you should probably do is have your loaded files dispatch an event and have the main file assign listeners to those loaded files. That way your loaded files are independent of the parent file and the parent file is independent of the loaded files, but together they can work things out.
Example:
Add something to trigger the event in the child:
dispatchEvent(new Event("eventTriggered"));
In your loading/parent swf, listen for the complete event on the Loader.contentLoaderInfo. In the complete event handler, add a listener for the event on the loaded swf.
// event handler triggered when external swf is loaded
function loaderCompleteHandler(event:Event) {
(event.currentTarget.content as MovieClip).addEventListener("eventTriggered", eventHandler);
}
function eventHandler(event:Event):void {
trace("event dispatched by loaded swf");
}

Copy link to clipboard
Copied
buy by doing this, it will not allow me to use the framesLoaded the way i am currently.....
i have my external swf file looping between frames 1 and 2 until it is completely loaded.....once its loaded i need it to tell the MAIN swf file that it can now gotAndPlay("start");
while the MAIN fla file is doing that, the external file will begin playing its timeline....so that the 2 together give the "load in" effect im looking for.....
i know before it was simple to do....you had your code on the main swf file with all the if/else statements for the pages....
and on the external swf file you had the tellTarget("targetname") bla bal bla called out.....
is there no simple way to do this in AS3? this is really getting frustrating and i was hoping that i didnt have to go some round about way by adding vars or listeners to achieve what im trying to do
Copy link to clipboard
Copied
If you prefer to not do things the more OO proper way, that's okay--I often avoid it myself. But to target the main timeline you need to realize where it is in relationship to the file you loaded. The parent of the loaded file is not the main timeline. Try tracing the parent of one of them and you will see who it is and maybe then can figure out where you need to point to get at the main timeline.

Copy link to clipboard
Copied
lol i know HOW to do it....
i was just wondering if there is a simpler way?
i dont feel like having to write in code for each possibility in my main file....
i was just hoping there was a quick easy way to target the main swf file from an external file WITHOUT the round about stuff
Copy link to clipboard
Copied
I've identified the two ways available for you to work it out, so if you're still stuck, back up to my last posting and try to work it out from there.

Copy link to clipboard
Copied
right.....im going with your first suggestion....
but i think im missing something here.....i am still kinda a newbie at this stuff....
i added your suggestion to the code ( at the end 😞
var Xpos:Number=0;
var Ypos:Number=0;
var swf:MovieClip;
var bgloader:Loader = new Loader();
var bgURL
if(page==1){
bgURL=new URLRequest("pages/home.swf");
}
if(page==2){
bgURL=new URLRequest("pages/about.swf");
}
if(page==3){
bgURL=new URLRequest("pages/updates.swf");
}
if(page==4){
bgURL=new URLRequest("pages/contact.swf");
}
bgloader.load(bgURL);
bgloader.x=Xpos;
bgloader.y=Ypos;
bg.addChild(bgloader);
stop();
function loaderCompleteHandler(event:Event) {
(event.currentTarget.content as MovieClip).addEventListener("eventTriggered", eventHandler);
}
function eventHandler(event:Event):void {
gotoAndPlay(41);
}
////////////////////////
and have also added the second part into the external swf....but i cant get them to communicate to each other....
i know ive got to be missing something stupid too....and probably embarassing.....
thanks for the help so far man.....you have definitely shown me a new method of going about this.....very much appreciated!
Copy link to clipboard
Copied
You may not need all of what you're trying to accomplish if you are just waiting for the swf to load before you command the main timeline to move along. If you assign a listener to the loader you can determine when the file is loaded and ready to run without having the file figure that out itself and tell you about it. Just add an INIT listener to your loader...
bgloader.contentLoaderInfo.addEventListener(Event.INIT, eventHandler);
That line of code will have your main timeline waiting to call that eventHandler function until the loader content (your swf) indicates that it is loaded and ready for action.
So all you might need is (meaning no code is needed in your loaded swf's)...
stop();
var Xpos:Number=0;
var Ypos:Number=0;
var swf:MovieClip;
var bgloader:Loader = new Loader();
var bgURL;
if(page==1){
bgURL=new URLRequest("pages/home.swf");
}
if(page==2){
bgURL=new URLRequest("pages/about.swf");
}
if(page==3){
bgURL=new URLRequest("pages/updates.swf");
}
if(page==4){
bgURL=new URLRequest("pages/contact.swf");
}
bgloader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
bgloader.load(bgURL);
bgloader.x=Xpos;
bgloader.y=Ypos;
bg.addChild(bgloader);
function initHandler(event:Event):void {
gotoAndPlay(41);
}
Taking one step back to what you tried just so the intentions of that solution aren't wasted... the missing link in your attempt was neglecting to add a listener for the load completion that would have called the loaderCompleteHandler function...
bgloader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler);

Copy link to clipboard
Copied
dude....i cant thank you enough for your patience and help!
i used a combination of both....and learned alot today man....i really do appreciate it!!!
you solved my dilema
Copy link to clipboard
Copied
You're welcome... it always helps to have options.

