A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] help with no repeat from random xml load

  1. #1
    Junior Member
    Join Date
    Feb 2003
    Posts
    10

    resolved [RESOLVED] help with no repeat from random xml load

    I have a script I've been using on many sites that randomly loads an image from an xml file, and it works great. It loads an image, the image plays for 90 frames, goes back to frame one and repeats.

    Now I'd like to enhance it so it doesn't repeat the last image, and I can't seem to get it to work. Any help would be great! Here's my original scritpt:


    Code:
    imgXML = new XML();
    imgXML.ignoreWhite = true;
    imgXML.onLoad = function(succes){
    if (succes){
    images = imgXML.firstChild.firstChild.childNodes;
    imageIndex = Math.round(Math.random()*(images.length-1));
    imageSRC = images[imageIndex].firstChild.nodeValue;
    imageURL = images[imageIndex].attributes.url;
    imageTARGET = images[imageIndex].attributes.target;
    
    doMenu(this);
    trace(imageSRC + " (" + imageURL + ")" + " (" + imageTARGET + ")");
    
    }
    }
    imgXML.load("/images/top_banner/top_banner.xml");
    function doMenu(xml:XML) { 
    empty_mc.loadMovie(imageSRC);
    main_button.onRelease = function () {
    getURL (imageURL, imageTARGET);
    }
    };

  2. #2
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    PHP Code:
    while(imageIndex == oldindex){
    imageIndex Math.round(Math.random()*(images.length-1));
    };
    oldIndex imageIndex

  3. #3
    Junior Member
    Join Date
    Feb 2003
    Posts
    10
    Thanks for the reply moagrius, but I still can't seem to get it to work. Perhaps I'm not understanding where to drop the code in, I've tried putting it in the if statement, in the doMenu function, I've put it just about everywhere. Any extra help would really... well...help.

  4. #4
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    PHP Code:
    var oldIndex 0;
    imgXML = new XML();
    imgXML.ignoreWhite true;
    imgXML.onLoad = function(succes){
    if (
    succes){
    images imgXML.firstChild.firstChild.childNodes;
    imageIndex Math.round(Math.random()*(images.length-1));
    while(
    imageIndex == oldIndex){ 
    imageIndex Math.round(Math.random()*(images.length-1)); 
    }; 
    oldIndex imageIndex
    imageSRC images[imageIndex].firstChild.nodeValue;
    imageURL images[imageIndex].attributes.url;
    imageTARGET images[imageIndex].attributes.target;

    doMenu(this);
    trace(imageSRC " (" imageURL ")" " (" imageTARGET ")");

    }
    }
    imgXML.load("/images/top_banner/top_banner.xml");
    function 
    doMenu(xml:XML) { 
    empty_mc.loadMovie(imageSRC);
    main_button.onRelease = function () {
    getURL (imageURLimageTARGET);
    }
    }; 

  5. #5
    Junior Member
    Join Date
    Feb 2003
    Posts
    10
    Thanks for all your help moagrius! I got it working. I realize what my mistake was now - I had the code set up like that before, but my timeline was screwy.

    When I wanted to load a new image, I realized that I only had to repass the imgXML.load and function doMenu code. Now it works great. Thanks!

  6. #6
    ___________________
    Join Date
    May 2004
    Posts
    3,174

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center