Scene remain on background after navigate to new file - actionscript-3

I cant stop the existing SWF after load another SWF. New SWF is run on top of the old SWF. I would like to know the simplest way to link all this up.
Scene 1
File 1: MainMenu.SWF (Consist of 2 Picture File)
- Subject1.JPG (Click and Load Subject1MainMenu.SWF)
- Subject2.JPG (Click and Load Subject2MainMenu.SWF)
Scene 2
File 2: Subject1MainMenu.SWF
Scene 3
File 3: Subject2MainMenu.SWF
Below is my code,
import flash.events.*;
var Subject1 = new Loader();
a.addEventListener(MouseEvent.CLICK,onMouseClick);
function onMouseClick (event:MouseEvent)
{
subject1.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
Subject1.load(new URLRequest("Subject1MainMenu.SWF"));
}
function onLoaderComplete(Event)
{
var mainmenu = subject1;
addChild(mainmenu);
}

There is no one size fits all to all this.
You can hide your main menu swf while you load and show child swf
you can remove your main menu completely while you show your child swf and later in some other flow, you reload your main menu again
you can also use module manager to manage the swf loading and unloading

Related

Cannot free memory of or unload flash swf

I'm using Adobe Animate CC with AS3. I'm having the following problem with my project (which has a lot of animation in it and hence is quite heavy)
There are 4 swf files which are in the same folder. The first one is like a blank container which loads the second swf automatically upon run. The second one has got a few buttons in it along with some animation. When the animation gets over, there is a button that loads the third swf. Now this 3rd swf has got a next button to load the next swf. The 4th swf has got back button to load the previous swf. The 3rd swf has in turn a home button that loads the 2nd swf.
Now, the problem is that when the next button is pressed, say on 2nd swf, not only should the 3rd swf open but the 2nd swf should get unloaded and the memory occupied by it should be freed. And same with the 3rd and the 4th swf.
However, the unloaded swf should open again when the back button is clicked.
If anyone could provide a link to or code for back button and load-unload, that'd be greatly appreciated.
I think it is much easier to load them all at once and then switch their visibility/attachment to the stage. However, if they are indeed too heavy to reside in the memory at once, you need a little trick to load them into a separate ApplicationDomain so they could be removed without anything left behind.
import flash.display.Loader;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.system.ApplicationDomain;
var aLoader:Loader = new Loader;
// Loading an SWF so it can be fully unloaded.
aLoader.load(new URLRequest("external.swf"), new LoaderContext(false, new ApplicationDomain));
// Unloading the loaded SWF.
aLoader.unloadAndStop(true);

AddChild to use external SWF has disabled my buttons I had on original Flash file

I have a Flash file (a website header with 5 buttons for 5 links to webpages).
On my actions layer, I added an external SWF file using the addChild object.
Note that I have very basic knowledge of ActionScript and I had to take some help from Google to setup above script.
The external SWF I have brought in using adChild code is working as an overlay on top of my original flash animation but all the buttons I have on original Flash file as website links have now become disabled. Even the mouseOver effects I applied to those 5 buttons are not responding. Below is my AS3 code:
import flash.net.navigateToURL;
import flash.net.URLRequest;
stop();
var swfRequest:URLRequest = new URLRequest("movie/txtOverlay.swf");
var swfLoader:Loader = new Loader();
swfLoader.load(swfRequest);
addChild(swfLoader);
button_1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
navigateToURL(new URLRequest("http://www.example.com/link1.asp"), "_self");
}
For the sake of brevity, I have placed just one button's code but you get the idea. Any solution to avoid this?
Thanks ... Syed

Actionscript - How to import swf with an html wrapper to timeline?

Afternoon,
I have a multiple choice quiz generated by a third party software which can export the quiz as an swf file.
The swf file comes with an html wrapper.(index.html)
It also creates a data folder that has a javascript file. No fla file is given.
My problem is...I'm working with flash cc to create a navigation menu so you click a button a video plays..then at the end of video you click and you take the quiz.
I am able to have the video stop and assign a click to it...What do i need to do to have the button call the swf file(when imported by itself comes up blank) or the index.html so the quiz will show up inside the timeline of the fla that i am working with?
I'm making a free training DVD for my students.
You can use the class Loader:
var loader:Loader = new Loader();
var url:URLRequest = new URLRequest("file.swf");
var loaderContext:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain, null);
loader.load(url, loaderContext);
When it's finished load, you can use it in you own actionscript file

AS3 my external swf file is overlapping with main swf file

i am new to AS3, i have been trying to setup a simple simulation in AS3 for 2 months.
i have pafanbalance1.swf file which just navigate from one scene to other and at the last scene loads a swf file named fescue.swf . it gets loadded easily but pafanbalance1.swf keep on overlapping with the fescue.swf which obviously i want to avoid. please help.
here is link to my .fla file on data hosting site.
http://www.datafilehost.com/d/3396ad6f
please help
In Scene 5 add stop in the Actions frame.
stop();
// CREATE A NEW LOADER OBJECT TO HOLD THE LOADED CONTENT
var holder:Loader = new Loader();
addChild(holder);
holder.load(new URLRequest("fescue.swf"));;

AS3 loading external swf on button click

In AS3 (Flash), I want an external swf-file to load when I click a specific menu button. I also want the swf to disappear when I click another button, so that another swf can load. This code shows my swf, but it just "loops". And also it covers my menu (on the top of the page) so I can't click anywhere. What could I change in the code to fix this?
var loader_mc : Loader = new Loader();
addChild(loader_mc);
bilder_btn.addEventListener(MouseEvent.CLICK, buttonClick)
function buttonClick(e:MouseEvent):void
{
try{
loader_mc.unloadAndStop();
} catch(e:Error) {
}
var urlRequest : URLRequest = new URLRequest("flickr.swf");
loader_mc.load(urlRequest);
}
Change loader_mc's X and Y so that the loaded SWF does not cover your menu.
You could do better with reinitializing that loader_mc to load another SWF, that is, create a new Loader(), removeChild() the old loader, addChild() the new one, then load.