Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 09-22-2008, 02:33 AM   #1
Tereba
Lost in Script...
 
Tereba's Avatar
 
Join Date: Sep 2008
Posts: 86
Question loading swf in container over other swf unloads previous swf??

okaay.. here is my doubt...

I have a main swf, which has the header of the website on top and buttons to navigate at the bottom. In the middle I have a container_mc where I load the swf's triggered by the bottom buttons.
Let's say, for simplicity sake, that I have 5 buttons - A, B, C, D and E, which load the A.swf, B.swf, C.swf, D.swf and E.swf files into the container.

My initial thought was that if I have A.swf loaded, and I click on B, that B.swf would load over A.swf, clearing A.swf from the website.
I am starting to think that is not so.
Note: I have no command to unload A.swf when I call B.swf. (because I assumed it was eliminated when a new swf was loaded)

The reason I think it isn't unloaded is because of 2 strange behaviors:

Strange behavior 1-
A.swf has a photo slideshow. I set the fade interval between the slides for 2.5 seconds. If I call B.swf, then call A.swf back again, the interval is smaller. If I repeat the above, the interval almost disappears.. I have the feeling it is loading one slideshow over the same slideshow...
This is the code:
Code:
//-----------OLD TV SLIDE PHOTO DISPLAY------------------------------

//: CALL IMPORT 
import flash.display.BitmapData;

//: SETUP VARIABLES
var maxTVval = 4;		// max number of fotos
var oldTVvar1 = 0;		// keep track of previous random number
var oldTVvar2 = 0;		// keep track of previous random number
var oldTVvar3 = 0;		// keep track of previous random number
var newTVvar = 0;		// used to load the next image
var si = 0;			// interval variable

//: LOAD THE NEXT IMAGE
function getImage() {
	newTVvar = Math.floor(Math.random() * maxTVval);								// get random number
	if (newTVvar == oldTVvar1 || newTVvar == oldTVvar2 || newTVvar == oldTVvar3) {	// if number = old number..
		getImage();																// get a number
	} else {																	// else
		oldTVvar3 = oldTVvar2;                                                      // set old to new number
		oldTVvar2 = oldTVvar1;                                                      // set old to new number
		oldTVvar1 = newTVvar;                                                       // set old to new number
        var linkageId:String = ("video" + newTVvar + ".jpg");						// load the next image
        var myBitmapData:BitmapData = BitmapData.loadBitmap(linkageId);			// get image from library
		TVpicscontainer_mc.attachBitmap(myBitmapData, this.getNextHighestDepth());	// attach image to container

		TVpicscontainer_mc._alpha = 0;												// set its alpha to 0
				TVpicscontainer_mc.onEnterFrame = fadeIn;								// start fading out
				delete this.onEnterFrame;										// delete loop
	}
}

//: FADE IN THE CURRENT MOVIECLIP
function fadeIn () {
	if (this._alpha <= 100) {					// if the movieclips alpha is greater than 0
		this._alpha += 5;						// reduce alpha by 5
	} else {									// else
		this._alpha = 100;						// reduce alpha to 0
		delete this.onEnterFrame;				// delete handler
		si = setInterval(fadeOut, 2500);		// after 2.5 seconds, fade out the movieclip
	}
}

//: FADE OUT THE CURRENT MOVIECLIP
function fadeOut () {
	clearInterval(si);							// clear the interval variable
	TVpicscontainer_mc.onEnterFrame = function() {	// create loop to fade out
		if (this._alpha >= 0) {					// if the movieclips alpha is greater than 0
			this._alpha -= 5;					// reduce alpha by 5
		} else {								// else
			this._alpha = 0;					// reduce alpha to 0
			delete this.onEnterFrame;			// delete handler
			getImage();							// load the next image
		}
	}
}

// load first image
getImage();

//-----------END OF MAIN SLIDE video DISPLAY---------------------------\\
Strange behavior 2 -
I have a toggle button, in the format of a flag, toggling the language chosen by the website visitor. The default is english (UK flag), but the visitor can choose portuguese (BR flag) in any of the swf files. The choice is stored in a global variable called _global.txtLanguage, and whenever visitor chooses a new swf by clicking on A, B, C, D or E the new swf has a onEnterFrame function to check what language is in the global variable and sends the flag_mc to the appropriate frame, displaying the alternative language flag on the toggle button. The problem is that when the swf file is called a second time only the defauld flag is displayed. A mouseover changes it correctly showing that _global.txtLanguage is correct. The feeling is that the onEnterFrame doesn't run except on the first time the swf is called. All subsequent calls do not trigger it.
This is the code:
Code:
//----------------Set Flag button-------------------------------

onEnterFrame = function () { 					//  when movie is called, do this function
	if (_global.txtLanguage != "port") {		//  check if language is different than portuguese
		flag_mc.gotoAndStop("br_flag");			//  if yes, goto and stop on the brazilian flag of the flag_mc movie
		delete this.onEnterFrame;				//  stop the onEnterFrame
	} else {
		flag_mc.gotoAndStop("uk_flag");			//  if no, goto and stop on the british flag of the flag_mc movie
		delete this.onEnterFrame;				//  stop the onEnterFrame
	}
}
So the questions that baffle me:
1) Why does the slideshow alter the fade interval upon reloads?
2) Why doesn't the toggle button run the onEnterFrame upon reloads?
3) Do I need to unload swf files before calling new swf files? What would be the proper code to do that ?

Any enlightment on my doubts are bound to receive my eternal gratitude
Best regards
Tereba is offline   Reply With Quote
Old 09-22-2008, 02:57 AM   #2
atomic
Banned by AS.org Staff
 
Join Date: Jan 2007
Location: Montréal, Québec
Posts: 14,073
Default

No, if you load another .swf in the same container, no unloading is necessary... It will automatically replace the previous .swf...

The problem you're describing is caused by not clearing the interval set in the previous movie... When loading a new movie, if the previous one was using a setInverval, you need to clear it, otherwise it continues to run, even if that previous movie is replaced with another one, and it will conflict with the new setInterval that will be set, if you reload that previous movie which was using the first interval...

Don't really know what's happening with your toggle button and the onEnterFrame...
Would have to see your .fla...
It may be that you're not using this.onEnterFrame but only onEnterFrame at the top of the function, and then supposedly deleting it with this.onEnterFrame...
I'd stick a trace in there to see if your onEnterFrame is in fact deleted or not, and/or add this.onEnterFrame at the top...

Another thing I can say is that, although I've used _global variables extensively up to MX2004, Flash 8 and higher versions, don't seem to like them at all... It may or not be part of the problem, but in any case I would try to avoid the use of _global variables (those birds didn't even ever exist outside of Flash) and I would just define it as a _level0 (main timeline) variable and just refer and/or set it from anywhere, referencing it with _level0.txtLanguage...

Last edited by atomic; 09-22-2008 at 03:00 AM.
atomic is offline   Reply With Quote
Old 09-22-2008, 02:45 PM   #3
Tereba
Lost in Script...
 
Tereba's Avatar
 
Join Date: Sep 2008
Posts: 86
Default

Hi Atomic, thanks again for stepping up to the plate

Here's what I did and other comments:
1) Regarding setInterval()
I searched the web on how to use clearInterval(), and it is quite straightforward. The problem, however, is that I would like to clear the interval when I exit the page. So I searched for an onExitFrame equivalent and found to be none.. is that correct? Is there a way to call clearInterval() when exiting the swf? I have another interval running when I open the webpage, which also would need clearing when loading a new swf.
An alternative would be to stick the clearInterval() call in every button that calls a new swf, but I imagine there must be a more elegant way to do it... any ideas?

2) Regarding the toggle button
You suggested 2 approaches, I'll address both:
2.1) to add the this.onEnterFrame at the top of the function.
I did it but nothing changed...
2.2) Replace _global.txtLanguage with _level0.txtLanguage
Also did this, but not only it didn't correct the behavior, as it made the toggle button even more erratic. Before as one chooses a language, it "stuck" across different swf calls. With the _level0.txtLanguage variable, if you change the default language, which is english, and change swfs the loaded swf reverts back to the default language instead of the chosen one
As you mentioned it would be necessary to se the fla files, here they go: (I tried uploading all of them, but there is a limit, so I will upload the rest of the files in another post.)

Thank you in advance!
Attached Files
File Type: zip files.zip (380.0 KB, 278 views)
Tereba is offline   Reply With Quote
Old 09-22-2008, 02:46 PM   #4
Tereba
Lost in Script...
 
Tereba's Avatar
 
Join Date: Sep 2008
Posts: 86
Default

and here go the rest of the files:
Best regards,
Attached Files
File Type: zip files2.zip (462.1 KB, 256 views)
Tereba is offline   Reply With Quote
Old 09-22-2008, 03:37 PM   #5
atomic
Banned by AS.org Staff
 
Join Date: Jan 2007
Location: Montréal, Québec
Posts: 14,073
Default

Do you that many buttons?
I know of no other simple way, in your situation, but to clear the interval on every other button that would clear, unload or replace the slideshow.swf...

Unless maybe using yet another onEnterFrame (always running), checking if the content of the container clip is in fact the slideshow.swf, and if it is do nothing, or if it isn't then clear the interval...

I'll try to have a look at your files...
atomic is offline   Reply With Quote
Old 09-22-2008, 04:10 PM   #6
atomic
Banned by AS.org Staff
 
Join Date: Jan 2007
Location: Montréal, Québec
Posts: 14,073
Default

In the 15 or more folders you have in the posted/attached files, I can't find a ttalbot_photos.fla, nor can I identify which .fla is the main movie's .fla, if there is one included...

Not much I can do with .swfs!

Can't you just attach and zip up the relevant files without including all those folders?
atomic is offline   Reply With Quote
Old 09-22-2008, 05:55 PM   #7
Tereba
Lost in Script...
 
Tereba's Avatar
 
Join Date: Sep 2008
Posts: 86
Default

hmm.. I must've maken a mistake when zipping the files.. I checked the "Save full path info" , and that messed things up when unzipping.. sorry about that.

I have zipped all files again, and this time into a single zip file (did you see there were 2 files? odd that you didn't find the .fla files)
Click here to download: www.ttalbot.com/test/

The directory structure is simple, and the unzipping will do it ( I tested), with the Flash files at the root directory and the text and script files in a lower directory.

This is how the Flash files relate to each other:

+--main swf---(ttalbot_main.swf [ttalbot v8f.fla])
..........|
..........+---photos swf-------(ttalbot_photos.swf [ttalbot_photos v8g.fla])
..........|
..........+---videos swf-------(ttalbot_videos.swf [ttalbot_videos v3d.fla])

As you can see, the main flash file is ttalbot v8f.fla, which I rename the swf file to ttalbot_main.swf when I want to see how it runs with the html file. That way I don't need to change the code every version I create (and with my learning curve they are many!)

Hopefully now you are all set to look into the files
Thanks again!

PS. the password for the swf file is "test"

Last edited by Tereba; 09-22-2008 at 07:00 PM.
Tereba is offline   Reply With Quote
Old 09-22-2008, 09:54 PM   #8
atomic
Banned by AS.org Staff
 
Join Date: Jan 2007
Location: Montréal, Québec
Posts: 14,073
Default

Still missing the ttalbot_home.swf, or is that the same as the ttalbot_main.swf?
atomic is offline   Reply With Quote
Old 09-23-2008, 01:31 AM   #9
Tereba
Lost in Script...
 
Tereba's Avatar
 
Join Date: Sep 2008
Posts: 86
Default

hi Atomic
ttalbot_home isn't relevant, that's why I didnt include it.. it's just a page that summarizes the website. The main, level 0, swf is ttalbot_main, or the ttalbot v8f.fla file. This is the swf that calls the other swfs..
Thanks
Tereba is offline   Reply With Quote
Old 09-23-2008, 02:37 AM   #10
atomic
Banned by AS.org Staff
 
Join Date: Jan 2007
Location: Montréal, Québec
Posts: 14,073
Default

Still confused!

So where is this slideshow movie with the interval supposedly loaded in ttalbot_main?

Oh, just saw the TV images freaking out when re-loading the videos movie... So I guess it's that one, right?

It's got nothing to do with the 4 cycling pictures when the main movie opens up, right?
atomic is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SWF loading a SWF with an FLV in it Cocytus ActionScript 3.0 1 09-18-2008 06:19 PM
Problem Loading external swf in a scrollpane alvin009 Components 7 05-01-2008 10:50 AM
Loading dynamic text passing to another SWF kelloggfan ActionScript 2.0 0 04-22-2008 08:59 PM
Problem loading swf into existing swf Frosty1_4me ActionScript 2.0 17 08-10-2007 04:40 AM
Loading external swf, then loading data... mike248 Other Flash General Questions 1 05-27-2007 02:11 AM


All times are GMT. The time now is 11:03 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.