hello,
I have some trouble about a setInterval not being cleared.
I made an index-intro.swf file that is being loaded into _root.mccontent.
This index-intro.swf has got the following code with a setInterval in function firstimage:
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
}
firstImage();
} else {
content = "file not loaded!";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("index-intro.xml");
/////////////////////////////////////
preloader._visible = false;
/////////////////////////////////////
function firstImage() {
clearInterval(sI);
// timed interval that will kick off 'firstImage' every 4 seconds
sI = setInterval(firstImage,4000);
p = Math.floor(Math.random() * total);
preloadthing();
}
/////////////////////////////////////
function preloadthing() {
imageholder.mcimage.loadMovie(image[p], 1);
imageholder._alpha = 0;
mcVlak._alpha = 0;
this.onEnterFrame = function() {
filesize = imageholder.mcimage.getBytesTotal();
loaded2 = imageholder.mcimage.getBytesLoaded();
percentage = Math.floor((loaded2/filesize)*100);
if (loaded2 != filesize) {
preloader._visible = true;
preloader.progressbar._xscale = percentage;
// set the percentage dynamic textfield
preloader.progresstxt.perc.text = percentage+"%";
}
// filesize > 1000 bytes is 1 kbyte
else if (loaded2 == filesize && filesize > 1000) {
preloader._visible = false;
// klaar met laden dus NU kan het plaatje worden geresized
resizePic(); // aanroepen van function resizePic
}
}
}
/////////////////////////////////////
function resizePic() {
// ratio van het in te laden plaatje berekenen
var ratioPic:Number;
imageW = imageholder.mcimage._width
imageH = imageholder.mcimage._height
ratioPic = imageH/imageW;
// ratio van het de stage berekenen
var ratioStage:Number;
stageW = Stage.width-136;
stageH = Stage.height
ratioStage = stageH/stageW;
// bepaal nieuwe breedte en hoogte van de container door middel van de verhouding van het plaatje
if (ratioStage>ratioPic) {
imageholder._width = stageW;
imageholder._height = stageW*ratioPic;
mcVlak._visible = false;
}
if (ratioStage<ratioPic) {
imageholder._width = stageH/ratioPic;
imageholder._height = stageH;
mcVlak._visible = true;
mcVlak._x = imageholder._width;
mcVlak._y = 0;
mcVlak._width = Stage.width-136;
mcVlak._height = Stage.height;
}
// fadein van de container
if (imageholder._alpha<100 || mcVlak._alpha<100) { // operator || or
imageholder._alpha += 10;
mcVlak._alpha += 10;
}
if (imageholder._alpha>=20) {
preloadinadvance(); // volgend plaatje alvast inladen
}
if (imageholder._alpha>=100 && mcVlak._alpha>=100) { // operator && and
delete this.onEnterFrame; // bespaar de cpu
}
}
/////////////////////////////////////
//listener aanmaken om te checken of de browser qua afmetingen veranderd
StageSizeListener = new Object();
StageSizeListener.onResize = function() {
// stretchen van de layout
resizePic();
}
Stage.addListener(StageSizeListener);
The above code is working, but when I click on a button to load a project.swf into _root.mccontent. it is still using the setinterval code within the firstImage function. This is the code for the project.swf:
// http://www.kirupa.com/developer/mx2004/xml_flash_photogallery9.htm
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
}
firstImage();
} else {
content = "file not loaded!";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("prj-won-markiezenhof.xml");
/////////////////////////////////////
p = 0;
// preloader positie en niet/wel zichtbaar
preloader._visible = false;
preloader._x = -136; // idem als x positie logo
preloader._y = 260;
// bepaal de _x en _y van de container waar het plaatje in wordt geladen
imageholder._x = 0;
imageholder._y = 0;
imagepreholder._visible = false; // hier wordt het volgende plaatje alvast in geladen, soort van preload
/////////////////////////////////////
function firstImage() {
preloadthing();
Buttons(); // aanroepen van functie buttons
}
function nextImage() {
if (p<(total-1)) {
p++;
preloadthing();
}
}
function prevImage() {
if (p>0) {
p--;
preloadthing();
} /*else {
loadMovie("prj-won-overzicht.swf", _root.mccontent);
}*/
}
function picture_num() {
current_pos = p+1;
mcinfo.pos_txt.text = current_pos+"/"+total;
}
/////////////////////////////////////
// xy positie buttons en mcinfo
function Buttons() {
mcinfo._x = -92;
bttnback._x = -136;
bttnnext._x = -50;
bttnback._y = Stage.height-60;
bttnnext._y = Stage.height-60;
mcinfo._y = Stage.height-40;
// begin if statement voor buttons
// menuhfd schuift met -500 tov stageheight
if (bttnback._y <= 630) {
bttnback._y = 630;
bttnnext._y = 630;
mcinfo._y = 650;
} // einde if statement
}
/////////////////////////////////////
function preloadthing() {
imageholder.mcimage.loadMovie(image[p], 1);
imageholder._alpha = 0;
mcVlak._alpha = 0;
picture_num();
this.onEnterFrame = function() {
filesize = imageholder.mcimage.getBytesTotal();
loaded2 = imageholder.mcimage.getBytesLoaded();
percentage = Math.floor((loaded2/filesize)*100);
if (loaded2 != filesize) {
preloader._visible = true;
preloader.progressbar._xscale = percentage;
// set the percentage dynamic textfield
preloader.progresstxt.perc.text = percentage+"%";
}
// filesize > 1000 bytes is 1 kbyte
else if (loaded2 == filesize && filesize > 1000) {
preloader._visible = false;
// klaar met laden dus NU kan het plaatje worden geresized
resizePic(); // aanroepen van function resizePic
}
}
}
/////////////////////////////////////
function resizePic() {
// ratio van het in te laden plaatje berekenen
var ratioPic:Number;
imageW = imageholder.mcimage._width;
imageH = imageholder.mcimage._height;
ratioPic = imageH/imageW;
// ratio van het de stage berekenen
var ratioStage:Number;
stageW = Stage.width-136;
stageH = Stage.height;
ratioStage = stageH/stageW;
// bepaal nieuwe breedte en hoogte van de container door middel van de verhouding van het plaatje
if (ratioStage>ratioPic) {
imageholder._width = stageW;
imageholder._height = stageW*ratioPic;
mcVlak._visible = false;
}
if (ratioStage<ratioPic) {
imageholder._width = stageH/ratioPic;
imageholder._height = stageH;
mcVlak._visible = true;
mcVlak._x = imageholder._width;
mcVlak._y = 0;
mcVlak._width = Stage.width-136;
mcVlak._height = Stage.height;
}
// kleur mcVlak relateren aan kleur balk met logo
if (_root.k==2) { // k=2 is kleur rood
var colormcVlak = new Color("mcVlak");
colormcVlak.setRGB(0xE5342C); // rood
}
if (current_pos == total) {
bttnnext._visible = false;
} else {
bttnnext._visible = true;
}
if (total == 1) {
bttnnext._visible = false;
bttnback._visible = false;
}
// fadein van de container
if (imageholder._alpha<100 || mcVlak._alpha<100) { // operator || or
imageholder._alpha += 10;
mcVlak._alpha += 5;
}
if (imageholder._alpha>=20) {
preloadinadvance(); // volgend plaatje alvast inladen
}
if (imageholder._alpha>=100 && mcVlak._alpha>=100) { // operator && and
delete this.onEnterFrame; // bespaar de cpu
}
}
/////////////////////////////////////
function preloadinadvance() {
imagepreholder.mcimage.loadMovie(image[p+1], 1);
}
/////////////////////////////////////
//listener aanmaken om te checken of de browser qua afmetingen veranderd
StageSizeListener = new Object();
StageSizeListener.onResize = function() {
// stretchen van de layout
resizePic();
Buttons();
}
Stage.addListener(StageSizeListener);
What am I doing wrong?
I can’t figure it out.