Solved

Flash xml Picture rotator Cache issue

Posted on 2008-10-12
4
569 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
  • 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now