Solved

Flash xml Picture rotator Cache issue

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
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.

749 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