Solved

Flash xml Picture rotator Cache issue

Posted on 2008-10-12
4
580 Views
Last Modified: 2013-11-11
Hello, I'm using the code below for a flash picture rotator that uses an xml file that I create when the user lands on a particular page. Each page may have different images that will rotate in the rotator. My issue is cache on the client. The images do not change even though the xml file has different images then the initial xml file.  I'm trying to modify the original author's code for the rotator by changing the load method. I read that this is possible from another site. I have to admit that my flash skills are lacking and I need some help here.

Here is the actionscript. The error in on the load method.

How can I get this to work??

/****************************/
/* Crossfading slide show   */
/* Author: Todd Dominey     */
/* http://whatdoiknow.org   */
/* http://domineydesign.com */
/****************************/

// set random # variables - each must be 0 for first 'while' loop below
var randomNum = 0;
var randomNumLast = 0;

// parent container
var container_mc = this.createEmptyMovieClip("container",0);
// movie clip containers
container_mc.createEmptyMovieClip("loader1_mc",2);
container_mc.createEmptyMovieClip("loader2_mc",1);

// preload watcher
this.createEmptyMovieClip("watcher_mc",100);

// load xml
images_xml = new XML();
images_xml.ignoreWhite=true;
images_xml.onLoad = parse;
//images_xml.load("images.xml");
images_xml.load("images.xml?+Math.random());
//xml.load(xmlFile.xml?+Math.random());
function parse(success) {
      if (success) {
            imageArray = new Array();
            var root = this.firstChild;
            _global.numPause = Number(8 * 1000);
            _global.order = 'sequential';
            _global.looping = 'yes';
            _global.fadetime = 2;
            _global.xpos =0;
            _global.ypos = 0;
            var imageNode = root.lastChild;
            var s=0;
            while (imageNode.nodeName != null) {
                  imageData = new Object;
                  imageData.path = imageNode.attributes.path;
                  imageArray[s]=imageData;
                  imageNode = imageNode.previousSibling;
                  s++;
            }
            // place parent container
            container_mc._x = _global.xpos;
            container_mc._y = _global.ypos;
            // parse array
            imageArray.reverse();
            imageGen(imageArray);
      } else {
            trace('problem');
      }
}

// depth swapping
function swapPlace(clip,num) {
      eval(clip).swapDepths(eval("container_mc.loader"+num+"_mc"));
}

function loadImages(data,num) {
      if (i==undefined || i == 2) {
            i=2;
            createLoader(i,data,num);
            i=1;
      } else if (i==1) {
            createLoader(i,data,num);
            i=2;
      }
}
function createLoader(i,data,num) {
      thisLoader=eval("container_mc.loader"+i+"_mc");
      thisLoader._alpha=0;
      thisLoader.loadMovie(data[num].path);
      watcher_mc.onEnterFrame=function () {
            var picLoaded = thisLoader.getBytesLoaded();
            var picBytes = thisLoader.getBytesTotal();
            if (isNaN(picBytes) || picBytes < 4) {
                  return;
            }
            if (picLoaded / picBytes >= 1) {
                  swapPlace("container_mc.loader2_mc",1);
                  alphaTween = new mx.transitions.Tween(thisLoader, "_alpha", mx.transitions.easing.Regular.easeOut,0,100,_global.fadetime,true);
                  timerInterval = setInterval(imageGen,_global.numPause,data);
                  delete this.onEnterFrame;
            }
      }
}
function imageGen(data) {
      // random, or sequential?
      if (_global.order=="random") {
            // choose random # between 0 and total number of images
            while (randomNum == randomNumLast) {
                  randomNum = Math.floor(Math.random() * data.length);
                  trace(randomNum);
            }
            loadImages(data,randomNum);
            randomNumLast = randomNum;
      } else if (_global.order=="sequential") {
            // start at 0, increment to total number of images, then drop back to zero when done
            if (p==undefined || p==data.length && _global.looping=="yes") { p=0; } else { break; }
            loadImages(data,p);
            p++;
      } else {
            trace ("order attribute in xml isn't correct - must specify either 'random' or 'sequential'");
      }
      clearInterval(timerInterval);
}
stop();
0
Comment
Question by:gogetsome
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:blue-genie
ID: 22703398
do u have 1 swf file that you use on a number of pages?
how are you triggering this when you say a person "lands on a particular page"
0
 

Author Comment

by:gogetsome
ID: 22703846
Hello, thanks for your help. I have one swf that I embed on all pages and change the images.xml per page load. The site is written in asp.net. When the page loads I select from the database the images that the picture rotator (the swf) will need to display on that particular page. During that event I create a new images.xml file and overright the old one. As we know flash has an issue when doing this sort of operation due to cache. This images_xml.load("images.xml?+Math.random()); is supposed to make the swf think it is loading a new images.xml(which it really is) thus not pulling the old one from cache. Unfortuanatly it is not working and gives an error when I want to compile the swf.
0
 
LVL 39

Accepted Solution

by:
blue-genie earned 500 total points
ID: 22705166
i only found out about the ? thing the other day myself. was a "hack" some php guys taught me.
would you be willing to try something - if you put a textbox in the flash files to output what xml its loading is it the right stuff. (or whatever runtime debug you have available).
not sure  - have to sleep on this.
0
 

Author Comment

by:gogetsome
ID: 22705470
yeah, me too. I will give it a shot and get back.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question