# Randomness hopelessness

**URL:** <https://forum.kirupa.com/t/randomness-hopelessness/204365>\
**Category:** Uncategorized\
**Created:** [October 19, 2006, 7:24am UTC](https://forum.kirupa.com/t/randomness-hopelessness/204365 "2006-10-19T07:24:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![TonyGrgurevic](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@TonyGrgurevic](https://forum.kirupa.com/u/TonyGrgurevic)\
**Post date:** [October 19, 2006, 7:24am UTC](https://forum.kirupa.com/t/randomness-hopelessness/204365/1 "2006-10-19T07:24:35Z")

</div>

I have a AS2 slideshow that plays through a few dynamic (XML) images, but I would like to randomize which image is being displayed…

I have searched the forums looking for how to do this but I cant get anything workin…

Any help is appreciated

cheers,  
:thumb2:

here is all the code:

```
 ActionScript Code:
 [FONT=Courier New][LEFT][COLOR=#808080]*#include "lmc_tween.as"*[/COLOR]

```

[COLOR=#808080]_//_\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[/COLOR]

[COLOR=#808080]_// baseurl to use to locate images based on SWF url not HTML url_[/COLOR]  
[COLOR=#808080]_//var baseurl = \_url.substr(0,\_url.lastIndexOf("/")+1);_[/COLOR]

[COLOR=#808080]_// create and position empty clips for images_[/COLOR]  
[COLOR=#808080]_// one for visible image, one which will be [/COLOR]  
[COLOR=#808080]// used for preloading the next image_[/COLOR]  
[COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]createEmptyMovieClip[/COLOR]COLOR=#000000[/COLOR]; [COLOR=#808080]_// on top_[/COLOR]  
[COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]createEmptyMovieClip[/COLOR]COLOR=#000000[/COLOR];  
one.[COLOR=#0000ff]\_x[/COLOR] = two.[COLOR=#0000ff]\_x[/COLOR] = [COLOR=#000080]0[/COLOR];  
one.[COLOR=#0000ff]\_y[/COLOR] = two.[COLOR=#0000ff]\_y[/COLOR] = [COLOR=#000080]30[/COLOR];

[COLOR=#808080]_// clips represents the clips with images_[/COLOR]  
clips = [COLOR=#000000][[/COLOR]one,two[COLOR=#000000]][/COLOR];  
timeline = [COLOR=#0000ff]this[/COLOR]; [COLOR=#808080]_// allows reference to timeline from other clips_[/COLOR]  
[COLOR=#808080]_// images is an array of the names of the images being used_[/COLOR]  
[COLOR=#808080]_// this is for file referencing as well as status display_[/COLOR]  
[COLOR=#000000] **function** [/COLOR] loadXMLCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000ff]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000ff]xmlNode[/COLOR] = [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]firstChild[/COLOR];  
images = [COLOR=#000000][[/COLOR][COLOR=#000000]][/COLOR];  
description = [COLOR=#000000][[/COLOR][COLOR=#000000]][/COLOR];  
total = [COLOR=#0000ff]xmlNode[/COLOR].[COLOR=#0000ff]childNodes[/COLOR].[COLOR=#0000ff]length[/COLOR];  
[COLOR=#0000ff]for[/COLOR] [COLOR=#000000]([/COLOR]i=[COLOR=#000080]0[/COLOR]; i\<total; i++[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
images[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR] = [COLOR=#0000ff]xmlNode[/COLOR].[COLOR=#0000ff]childNodes[/COLOR][COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#0000ff]childNodes[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#0000ff]firstChild[/COLOR].[COLOR=#0000ff]nodeValue[/COLOR];  
description[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR] = [COLOR=#0000ff]xmlNode[/COLOR].[COLOR=#0000ff]childNodes[/COLOR][COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#0000ff]childNodes[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#0000ff]firstChild[/COLOR].[COLOR=#0000ff]nodeValue[/COLOR];

```
    [COLOR=#000000]}[/COLOR]
    status_txt.[COLOR=#0000ff]text[/COLOR] = [COLOR=#ff0000]"xml is loaded!"[/COLOR];
    FirstLoad[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
    [COLOR=#808080]*//PreloadNext();*[/COLOR]
    [COLOR=#808080]*//next_one();*[/COLOR]
    
[COLOR=#000000]}[/COLOR] [COLOR=#0000ff]else[/COLOR] [COLOR=#000000]{[/COLOR]
    status_txt.[COLOR=#0000ff]text[/COLOR] = [COLOR=#ff0000]"file not loaded!"[/COLOR];
[COLOR=#000000]}[/COLOR]

```

[COLOR=#000000]}[/COLOR]  
xmlData = [COLOR=#000000] **new** [/COLOR] [COLOR=#0000ff]XML[/COLOR]COLOR=#000000[/COLOR];  
xmlData.[COLOR=#0000ff]ignoreWhite[/COLOR] = [COLOR=#000000] **true** [/COLOR];  
xmlData.[COLOR=#0000ff]onLoad[/COLOR] = loadXML;  
xmlData.[COLOR=#0000ff]load[/COLOR]COLOR=#000000[/COLOR];

[COLOR=#000000] **function** [/COLOR] GetFileForCOLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#0000ff]return[/COLOR] +[COLOR=#0000ff]name[/COLOR];  
[COLOR=#000000]}[/COLOR]

[COLOR=#808080]_// Preload checks to see if a clip has been loaded_[/COLOR]  
[COLOR=#000000] **function** [/COLOR] PreloadCOLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] lod = clip.[COLOR=#0000ff]getBytesLoaded[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000] **var** [/COLOR] tot = clip.[COLOR=#0000ff]getBytesTotal[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]lod && tot[COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] percent\_loaded = lod/tot;  
progress\_mc.[COLOR=#0000ff]\_xscale[/COLOR] = [COLOR=#000080]100[/COLOR]\* percent\_loaded;  
[COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]lod == tot[COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]  
status\_txt.[COLOR=#0000ff]text[/COLOR] = [COLOR=#ff0000]"Preloading complete for "[/COLOR]+images[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR];  
[COLOR=#0000ff]return[/COLOR] [COLOR=#000000] **true** [/COLOR]; [COLOR=#808080]_// is complete_[/COLOR]  
[COLOR=#808080]_//progress\_mc.\_visible = false;_[/COLOR]

```
    [COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#0000ff]return[/COLOR] [COLOR=#000000] **false** [/COLOR]; [COLOR=#808080]*// is not complete*[/COLOR]

```

[COLOR=#000000]}[/COLOR]

[COLOR=#808080]_// PreloadNext is used as an onEnterFrame event_[/COLOR]  
[COLOR=#808080]_// to check the loading of the current image and [/COLOR]  
[COLOR=#808080]// reorders the arrays so that the first element_[/COLOR]  
[COLOR=#808080]_// now represents the next image/clip_[/COLOR]  
[COLOR=#000000] **function** [/COLOR] PreloadNextCOLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] is\_complete = PreloadCOLOR=#000000[/COLOR];  
[COLOR=#808080]_//progress\_mc.\_visible = true;_[/COLOR]  
[COLOR=#0000ff]if[/COLOR] COLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]  
clips.[COLOR=#0000ff]push[/COLOR]COLOR=#000000[/COLOR]; [COLOR=#808080]_// shift order of arrays_[/COLOR]  
images.[COLOR=#0000ff]push[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#808080]_//Pauser();_[/COLOR]  
[COLOR=#0000ff]delete[/COLOR] [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]onEnterFrame[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR]

[COLOR=#808080]_// initiate loading of first image_[/COLOR]  
clips[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#0000ff]loadMovie[/COLOR]COLOR=#000000[/COLOR];  
status\_txt.[COLOR=#0000ff]text[/COLOR] = [COLOR=#ff0000]"Preloading "[/COLOR]+images[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR];  
[COLOR=#808080]_[//black.swapDepths](https://black.swapDepths)(100);_[/COLOR]

[COLOR=#808080]_// FirstLoad is like PreloadNext but loads the first image_[/COLOR]  
[COLOR=#808080]_// adding in a status message otherwise handled by the next button_[/COLOR]  
[COLOR=#808080]_// and starting the second image to load when complete._[/COLOR]  
[COLOR=#000000] **function** [/COLOR] FirstLoadCOLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] is\_complete = PreloadCOLOR=#000000[/COLOR];  
[COLOR=#0000ff]if[/COLOR] COLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]  
clips.[COLOR=#0000ff]push[/COLOR]COLOR=#000000[/COLOR];  
images.[COLOR=#0000ff]push[/COLOR]COLOR=#000000[/COLOR];  
clips[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#0000ff]loadMovie[/COLOR]COLOR=#000000[/COLOR];  
status\_txt.[COLOR=#0000ff]text[/COLOR] = [COLOR=#ff0000]"Preloading "[/COLOR]+images[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR];  
timeline.[COLOR=#0000ff]onEnterFrame[/COLOR] = PreloadNext;  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR]

[COLOR=#808080]_//calls a function called GoBack every 4 seconds//_[/COLOR]

[COLOR=#808080]_// next\_btn.onPress shows the next image if preloaded and starts_[/COLOR]  
[COLOR=#808080]_// preloading the next one using PreloadNext as an onEnterFrame event_[/COLOR]  
next\_one = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#0000ff]if[/COLOR] COLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]  
status\_txt.[COLOR=#0000ff]text[/COLOR] = [COLOR=#ff0000]“Please wait for “[/COLOR]+images[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR]+[COLOR=#ff0000]” to complete”[/COLOR];

```
[COLOR=#000000]}[/COLOR]
[COLOR=#808080]*//clips[0]._alpha = 100;*[/COLOR]
[COLOR=#808080]*//clips[1]._alpha = 0;*[/COLOR]

clips[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#0000ff]swapDepths[/COLOR][COLOR=#000000]([/COLOR]clips[COLOR=#000000][[/COLOR][COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#808080]*// move preloaded image to top*[/COLOR]
clips[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#0000ff]_alpha[/COLOR] = [COLOR=#000080]0[/COLOR];

clips[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#0000ff]loadMovie[/COLOR][COLOR=#000000]([/COLOR]images[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR][COLOR=#000000])[/COLOR];

status_txt.[COLOR=#0000ff]text[/COLOR] = [COLOR=#ff0000]"Preloading "[/COLOR]+images[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR];
timeline.[COLOR=#0000ff]onEnterFrame[/COLOR] = PreloadNext;
clips[COLOR=#000000][[/COLOR][COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#000080]alphaTo[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000080]100[/COLOR],[COLOR=#000080]3[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#808080]*//clips[0].alphaTo(100,1,1);*[/COLOR]

```

[COLOR=#000000]}[/COLOR]  
[COLOR=#0000ff]stop[/COLOR]COLOR=#000000[/COLOR];

Pauser = [COLOR=#0000ff]setInterval[/COLOR][COLOR=#000000]([/COLOR]GoNext, [COLOR=#000080]3000[/COLOR][COLOR=#000000])[/COLOR]

[COLOR=#000000] **function** [/COLOR] GoNextCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000ff]if[/COLOR][COLOR=#000000]([/COLOR]timeline.[COLOR=#000080]progress\_mc[/COLOR].[COLOR=#0000ff]\_xscale[/COLOR] == [COLOR=#000080]100[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#808080]_//clips[1].alphaTo(0,2);_[/COLOR]  
next\_oneCOLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR]  
[/LEFT]  
[/FONT]
