Hi,
I'm a newbie to Flash and Actionscript. I need to give links to around 20 swf files via buttons from the menu.swf. I'm able to give links. But when I come back by clicking HOME button kept at the newly loaded swf the audio files are still being played at the background.
Yes, It has got audio files playing at the back for each slide in the new swfs. When Click on the same link again in menu.swf again the files are being played with the unfinished old file. It's really hectic.
I need to unload it completely from stage when I come back to menu.swf by clicking on HOME button from any of 20 categories.
I used unloadAndStop but it is not doing. I hope that I'm commiting mistakes at somewhere but couldn't predict.
Need some help !
FOR HOME BUTTON:
var _content:Loader = new Loader();
function loadContent(content:String):void {
if (_content != null) {
_content.unloadAndStop(true);
removeChild(_content);
_content = null;
}
var loader:Loader = new Loader();
loader.load(new URLRequest(content)); //---->>>> I don't really know what should be put in this :-(
_content = addChild(loader) as Loader;
}
Home_Button.addEventListener(MouseEvent.CLICK, home);
function home(event:MouseEvent) {
_content.unloadAndStop(true);
var homeSWF:URLRequest = new URLRequest("demo.swf");
_content.load(homeSWF);
addChild(_content);
}
FOR MENU.swf button
var loader:Loader = new Loader();
Category1_Button.addEventListener(MouseEvent.CLICK, category1);
function category1(event:MouseEvent):void {
var Category1SWF:URLRequest = new URLRequest("Category1.swf");
loader.load(Category1SWF);
addChild(loader);
}
Hi kglad,
Thanks for replying in very short span of time. I'll put in this way.
Approx 20 buttons are on the stage - file named menu.swf. Each button will have link to separate swfs. Come to your valuable question. I need to load only one swf at one time.
The flow of the project is, Each swf will have around 10-12 slides with separate voice over associated with it. When one swf finishes it should automatically load the next swf.
But at any time from any swf the user should be able to come back to menu.swf by clicking on HOME button which is available on each swf.
Hope this sounds clear. Awaiting your valuable reply.
Thanks.
Hi,
I have actually added the bolded lines in both actionscripts. Now the audio gets stopped properly when I come back from category1 swf to menu.swf. But still the category1 swf stays on background.
When I use keyboard TAB key to navigate I can find those invisible buttons of category1 swf and able to click ( using spacebar ) on it even it is invisible. It starts playing the file at the background invisibily.
I found it by hearing the voice over of the slides. Hope you understand. I just want to unload the whatever category I load and come back to menu.swf. Need Help !!!
var _content:Loader = new Loader();
Home_Button.addEventListener(MouseEvent.CLICK, home);
function home(event:MouseEvent) {
_content.unloadAndStop(true);
SoundMixer.stopAll();
var homeSWF:URLRequest = new URLRequest("demo.swf");
_content.load(homeSWF);
addChild(_content);
}
FOR MENU.swf button
var loader:Loader = new Loader();
Category1_Button.addEventListener(MouseEvent.CLICK, category1);
function category1(event:MouseEvent):void {
var Category1SWF:URLRequest = new URLRequest("Category1.swf");
loader.load(Category1SWF);
SoundMixer.stopAll();
addChild(loader);
}
Thanks !
if you only need to load one swf at any one time, use one loader:
var _content:Loader = new Loader();
addChild(_content);
function loadContent(content:String):void {
if (_content.content != null) {
_content.unloadAndStop(true);
}
_content.load(new URLRequest(content));
}
Home_Button.addEventListener(MouseEvent.CLICK, home);
function home(event:MouseEvent) {
var homeSWF:URLRequest = new URLRequest("demo.swf");
if(_content.content){
_content.unloadAndStop();
}
_content.load(homeSWF);
}
FOR MENU.swf button
Category1_Button.addEventListener(MouseEvent.CLICK, category1);
function category1(event:MouseEvent):void {
var Category1SWF:URLRequest = new URLRequest("Category1.swf");
if(_content.content){
_content.unloadAndStop();
}
_content.load(Category1SWF);
}
Hi,
Thanks for your reply. I did replace the code with yours. When I'm on menu.swf I click on Category1.swf button. It plays the file and I can hear the sound but unable to see the display. It still stays on menu.swf and the background music of menu.swf mixes with Category1.swf file sound.
I meant the sound files of menu.swf and Category1.swf gets overlapped. Unable to see the Category1.swf display. I can only see menu.swf display.
Hope you understand.
My 4th reply works fine but Category1.swf stays on background as I told on that reply. Please have a look at and expecting your reply.
Thanks.
Hi,
I don't really understand that where are we calling loadContent function in the script ? I have placed the below codes for
Home Button:
var _content:Loader = new Loader();
addChild(_content); //------------------------------------->>>>> What will actually be add as a child here ?
function loadContent(content:String):void {
if (_content.content != null) {
_content.unloadAndStop(true);
}
_content.load(new URLRequest(content)); //------------------->>>> What content is this ? Default property ? //Why because we never declared this variable anywhere.
}
Home_Button.addEventListener(MouseEvent.CLICK, home);
function home(event:MouseEvent) {
var homeSWF:URLRequest = new URLRequest("demo.swf");
if(_content.content){
_content.unloadAndStop();
}
_content.load(homeSWF);
}
For Menu.swf Button:
Category1_Button.addEventListener(MouseEvent.CLICK, category1);
function category1(event:MouseEvent):void {
var Category1SWF:URLRequest = new URLRequest("Category1.swf");
if(_content.content){
_content.unloadAndStop();
}
_content.load(Category1SWF);
}
My 4th reply works fine but Category1.swf stays on background as I told on that reply. Please have a look at and expecting your reply.
Thanks.
use this code:
Home Button:
var _content:Loader = new Loader();
addChild(_content); // _content, a loader with no content is added to this timeline
function loadContent(content:String):void {
if (_content.content != null) {
_content.unloadAndStop(true);
}
_content.load(new URLRequest(content));
}
Home_Button.addEventListener(MouseEvent.CLICK, home);
function home(event:MouseEvent) {
var homeSWF:URLRequest = new URLRequest("demo.swf");
if(_content.content){
_content.unloadAndStop();
}
_content.load(homeSWF);
}
For Menu.swf Button:
Category1_Button.addEventListener(MouseEvent.CLICK, category1);
function category1(event:MouseEvent):void {
var Category1SWF:URLRequest = new URLRequest("Category1.swf");
if(_content.content){
_content.unloadAndStop();
}
_content.load(Category1SWF);
}
Hi,
Can this thread help us?
http://forums.adobe.com/message/3739886
I have seen you have replied to this. Would this give some idea ? Does this script serve the purpose ? I tried replacing the code with appropriate changes and looking like this.
Home Button:
var swf_loader:Loader = new Loader();
///unload previous swf
swf_loader.unloadAndStop();
removeChild(swf_loader);
////load new swf
swf_loader.load(new URLRequest("menu.swf"));
Home_Button.addEventListener(MouseEvent.CLICK, finishLoading);
function finishLoading(e:Event):void{
if(swf_loader.content){
addChildAt(swf_loader, 0);
}
}
but getting error as
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at Category1_fla::MainTimeline/frame55()
I think I'm complicating the simple thing. ![]()
Thanks.
Hi,
I have added that line in menu.swf button and plays the Category1.swf with menu.swf's BGM overlapping. When I click on Home button it comes back to menu.swf with Category1.swf voice over still plays at the background. The same thing happens as I mentioned in opening of thread.
For Menu.swf Button:
var _content:Loader = new Loader();
addChild(_content);
Category1_Button.addEventListener(MouseEvent.CLICK, category1);
function category1(event:MouseEvent):void {
var Category1SWF:URLRequest = new URLRequest("Category1.swf");
if(_content.content){
_content.unloadAndStop();
}
_content.load(Category1SWF);
}
This might be a simple thing. But I'm complicating this. ![]()
Please need some help !
Hi,
I think, I'm wasting your precious time. The suggested code by me on this thread opening makes us tangled. Let me put the things very clearly. You please review the below requirements and
Educate me with your OWN CODE suggestion or Whatever !
Hope this makes sense.
Requirements:
For instance, I have two swfs.
1. menu.swf
2. Category1.swf
1. Previous ---- Works
2. Next ---- Works
3. Replay --- Works
4. HOME --- Doesn't work ( Which points to menu.swf )
I just want to unload (including background music) menu.swf when go to Category1.swf and vice versa when clicking HOME button on Category1.swf
Please review this and advice.
Thanks in advance !
then from the main timeline in category1.swf, use:
Category1_Button.addEventListener(MouseEvent.CLICK, category1);
function category1(event:MouseEvent):void {
var menu:URLRequest = new URLRequest("menu.swf");
if(MovieClip(parent)._content.content){
MovieClip(parent)._content.unloadAndStop();
}
MovieClip(parent)._content.load(menu);
}
Hi,
Thank you so much for spending your time with me for writing and correctind codes. But The above code doesn't work for this project.
I don't have any movie clips anywhere in this project. I have all 21 swfs ( including menu.swf ) kept in one folder in the Operating System. I didn't keep any swf inside another or pasted in Timeline. No Movie clips. I want to keep menu.swf running initially. From there we can go to all 20 categories and come back to menu.swf by clicking on home button which is available on all 20 categories.
Awaiting your workable solution. To be honest I really appreciate your help. I hope we can sort out this issue in just couple of mins, If we are in chat or something related to that.
Thanks.
i think there's a terminology issue.
your main swf is the swf that is embedded by your html page. it is the first swf to be displayed and it cannot be unloaded using actionscript.
it should contain loader, the only Loader instance you need.
that main swf may or may not be main.swf.
in your main swf, you should use:
/////////////////////////////////
var loader:Loader = new Loader();
addChild(loader);
function loadF(fileS:String):void {
if(loader.content){
loader.unloadAndStop();
}
loader.load(new URLRequest(fileS));
addChild(loader);
}
function unloadF():void{
if(loader.content){
loader.unloadAndStop();
}
}
/////////////////////////////////////////
don't change anything between the ////// lines
----------------------------------------------------
from your main swf, if you want to load "catgoryxyz.swf", use:
loadF("categoryxyz.swf"); // this argument in this line you can and will change
from you main swf, if you want to unload whatever's been loaded (and appear to return to your main swf), use:
unloadF();
---------------------------------------------------
from the main timeline of any loaded swf (like categoryxyz.swf), if you want to load "categoryabc.swf", use:
MovieClip(this.parent.parent).loadF("categoryabc.swf"); // the argument in this line you can and will change
if you want a swf to unload itself (and appear to return to your main swf), use:
MovieClip(this.parent.parent).unloadF();
-----------------------------------------------------------------
Hi,
First of all, I'm so grateful for your help. You are spending so much time on this issue. I did the same thing you told on the above reply. It took me 4 hours to work around But still crazy issues are happening.
As you have told menu file is still sitting at background. Even I can hear the Background music even after I clicked on some category's button. menu.swf's BGM is playing 31 secs ( time limit i've set in Timeline ) and stops playing it. After I'm on any category, using KEYBOARD KEYS I can still choose the menu.swf buttons which are staying at background invisibily.
We are going to release this on CD-ROM + HTML version.
Some crazy issues are also there which I couldn't document here. What shall we do? Are there some possibilities for you have a look at the .fla files? Are there possibilities for you to come on chat ? We can sort out this issue then and there?
Need some help !
Thanks.
Hi,
Yes my dear flash grand master.
menu.swf is the first opening file. From here user can go to all 20 categories by clicking buttons which are available on menu.swf.
From any 20 categories they can come back to menu.swf by clicking home button.
Next category should be AUTOPLAYED, if they don't click on HOME button.
Please suggest me good ActionScript tutorial also.
Awaiting your reply.
Thanks.
Hi Grand Master ( kglad ),
As you had told in 23rd reply the initially loaded file can be unloaded using Actionscript I did little trick in order to get this work done. I have kept the intial swf as just a background with the same stage color of all other swfs (All swfs are going to have same stage color) without anything controls in it. I just added the loadF and unloadF functions in that.
I consider this as parent. I load menu.swf from this using loadF();
From menu.swf I call other categories by clicking buttons using
MovieClip(this.parent.parent).loadF("categoryabc.swf");
It seems to work right now. Let me complete this project and let you know.
I want to know one thing that would there be any memory overloading issue arise as one swf is always staying at back? But there is no controls in it. I even checked it and it doesn't exhaust machine's memory.
Thanks for your great and timely help. You really rock. ![]()
one swf (the main one or menu.swf in your situation) always remains loaded. you can stop all sounds in it (SoundMixer.stopAll() ) and you can position a stage colored and sized rectangle over everything in your main swf so it "appears" to be unloaded but you can't unload it.
and no, one swf will not overload memory unless it is creating more and more objects. you can use System.totalMemory in an enterframe loops (for example) to check whether you have a memory leak.
p.s. please mark helpful/correct responses, if there are any.
North America
Europe, Middle East and Africa
Asia Pacific