dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: How to load random images in XML

  1. #1
    Senior Member
    Join Date
    Oct 2007
    Posts
    121

    How to load random images in XML

    Hi I'm creating a battle scene where an background image is uploaded to flash using XML, if this is my basic code in XML like this
    PHP Code:
    var x:XML = new XML();
    x.ignoreWhite true;
     
    var 
    urls:Array = new Array(); 
    what should be the code in my main function where after every run it can load random images out of ten choices could some one show me how it is done thanks
    Last edited by cain_1st; 03-01-2008 at 09:03 AM.

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    in a nutshell -

    load the xml
    parse it into an array
    randomise the array
    pop the last element

    i'll leave the loading and parsing to you (no data supplied !)
    to randomise an array-

    function shuffle(){ return Math.floor(Math.random()*3)-1; }
    urls.sort(shuffle);


    to remove the last element of array urls -

    toLoad = urls.pop();
    trace(toLoad);

  3. #3
    Senior Member
    Join Date
    Oct 2007
    Posts
    121
    I've got it working already this is what my code look like
    for (i=0; i<totalImages; i++) {
    imageFileName[i] = xmlFirstChild.childNodes[0].childNodes[i].attributes.url;
    }
    randomImage();
    }
    }
    function randomImage() {
    if (loaded == filesize) {
    var ran = Math.round(Math.random() * (totalImages - 1));
    holder.loadMovie(imageFileName[ran], 1);

    }

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