View Full Version : Control main.swf through loaded.swf
damonlee3
June 7th, 2009, 05:07 PM
I'm trying to control my main.swf through a loaded .swf.
My goals are.
1. load the external swf into main.swf and have a movieclip in the external swf play.
(the movie clip in the external swf should play without any code, however, when the external swf loads, the movie clip goes to the last frame of itself for some reason)
2. I have an "X" button on the loaded.swf itself that should dismiss the loaded swf and cause my navigation on my main.swf to reappear.
Here is my loader code in main.swf:
var _urlx:Loader = new Loader();
_urlx.load(new URLRequest("loadBlank.swf"));
var _url1:Loader = new Loader();
_url1.load(new URLRequest("loadBio.swf"));
var _url2:Loader = new Loader();
_url2.load(new URLRequest("loadMedia.swf"));
function loadBlank(e:MouseEvent):void{
addChild(_urlx);
}
function loadBio(e:MouseEvent):void{
addChild(_url1);
}
function loadMedia(e:MouseEvent):void{
addChild(_url2);
}
Here is my code on the loaded.swf:
stop();
btnBack.buttonMode=true;
btnBack.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent) {
MovieClip(parent.parent).navAnimIn(null);
}
As of now, my navigation in main.swf does reappear when the "X" in the loaded.swf is clicked, but I need a way to unload the currently loaded swf when the "X" button is clicked..
I've tried remove child, checking to see if the loaded child is not null, but that didn't work either...
Any help would be greatly appreciated...
-Damon
trundrumbalind
June 7th, 2009, 07:01 PM
How about putting the X inside main.swf. Things will be neater and easier like that. Here's some code...
var closeButton : CloseButton = new CloseButton();
closeButton.visible = false;
closeButton.addEventListener(MouseEvent.CLICK, dismissExternalSWF);
var externalSWF : Loader = new Loader();
externalSWF.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, addExternalSWF);
externalSWF.load(new URLRequest("external.swf");
addChild(closeButton);
function addExternalSWF(e : Event) : void
{
externalSWF.content.gotoAndStop(1);
addChild(externalSWF);
closeButton.visible = true;
}
function dismissExternalSWF(e : MouseEvent) : void
{
this.removeChild(externalSWF);
closeButton.visible = false;
}
damonlee3
June 7th, 2009, 08:23 PM
How about putting the X inside main.swf. Things will be neater and easier like that. Here's some code...
var closeButton : CloseButton = new CloseButton();
closeButton.visible = false;
closeButton.addEventListener(MouseEvent.CLICK, dismissExternalSWF);
var externalSWF : Loader = new Loader();
externalSWF.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, addExternalSWF);
externalSWF.load(new URLRequest("external.swf");
addChild(closeButton);
function addExternalSWF(e : Event) : void
{
externalSWF.content.gotoAndStop(1);
addChild(externalSWF);
closeButton.visible = true;
}
function dismissExternalSWF(e : MouseEvent) : void
{
this.removeChild(externalSWF);
closeButton.visible = false;
}
Well, right now, that's what i have; the "X" is on the main.swf.
I just wanted the external SWF to be completely self contained...I will try out your code.
anyone else have any ideas?
damonlee3
June 8th, 2009, 03:34 AM
Ok, I figured out how to both control the main.swf by the loaded.swf and vice-versa.
Now, this code maybe able to written in a better way (I'm not a programmer per-se)
So, if some of you pros can come up with a better way then please share.
All I know is that this method of loading external swf's allows control of the external swf through a loaded swf and vice-versa...I'm re-stating this because other load methods have not allowed control of an external.swf through the main.swf navigation (and other way around)
Also, this load method replaces the loaded.swf with the next swf to be loaded...
All code is placed within the main.swf
Here is the loader code:
var _swfContainer:Loader = new Loader()
var _url1:URLRequest = new URLRequest("loadBio.swf")
var _url2:URLRequest = new URLRequest("loadMedia.swf")
var _externalMovie:MovieClip;
//Start loading and add the loader to the stage
stage.addChild(_swfContainer);
_swfContainer.contentLoaderInfo.addEventListener(f lash.events.Event.COMPLETE, finishedLoading);
// This is done after the swf is loaded
function finishedLoading (e:Event)
{
_externalMovie = MovieClip(_swfContainer.content);
}
Here is the code that allows functions to be written in main.swf that controls the movie clips of the external.swf:
function activateExternalSWFelements(e:MouseEvent):void{
///////// ACCESSING AN EXTERNAL SWF'S MOVIE CLIP///////////////////////////////////////////////////////////////
_swfContainer.contentLoaderInfo.addEventListener(f lash.events.Event.COMPLETE, finishedLoading);//necessary to see if ext swf has loaded before accessing movie clip in ext swf
function finishedLoading (e:Event){
//now that the external SWF has finished loading, we can manipulate it's elements
_externalMovie.pageTitle.alpha=0;
_externalMovie.btnBack.alpha=0;
_externalMovie.pageFlipOut.visible=false;
_externalMovie.pageFlipIn.alpha=0;
_externalMovie.btnBack.buttonMode=true;
Tweener.addTween(_externalMovie.pageTitle, {alpha:1, time:2, delay:1, transition:"easeInOutExpo"});
Tweener.addTween(_externalMovie.pageFlipIn, {alpha:0.5, time:2, delay:0, transition:"easeInOutExpo"});
Tweener.addTween(_externalMovie.btnBack, {alpha:1, time:2, delay:1, transition:"easeInOutExpo"});
_externalMovie.btnBack.addEventListener(MouseEvent .CLICK, navAnimIn);
_externalMovie.btnBack.addEventListener(MouseEvent .CLICK, closeCurrentPage);
_externalMovie.pageFlipIn.gotoAndPlay(2);
}
}
Notice that
swfContainer.contentLoaderInfo.addEventListener(fl ash.events.Event.COMPLETE, finishedLoading); is repeated in the function that access the external.swf movie clips.
Like I said, this code could probably be written better; this just worked for me.
The above code works in the following browsers (Mac and PC)
IE
Safari
Firefox
I appreciate the help I recieve from these forum...I just wanted to give some help back
Thank you
Damon
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.