Hey guys,
Im creating an xml driven matching game. It is workin pretty well at the moment, but the images are loaded from the xml in the order they are in. What I am wanting is everytime the movie is loaded the images are in random order. Tried using Math.random() with no joy, a point in the right direction would be great!
[COLOR=#f000f0]*//Import the XML*[/COLOR]
XMLfile = [COLOR=#0000ff]"images.xml"[/COLOR];
importXML = [COLOR=#993300]new[/COLOR] [COLOR=#993300]LoadVars[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
_xml = [COLOR=#993300]new[/COLOR] [COLOR=#993300]XML[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
_xml.[COLOR=#993300]ignoreWhite[/COLOR] = [COLOR=#993300]true[/COLOR];
_xml.[COLOR=#993300]onLoad[/COLOR] = [COLOR=#993300]function[/COLOR][COLOR=#000000]([/COLOR]success:[COLOR=#993300]Boolean[/COLOR][COLOR=#000000])[/COLOR]:[COLOR=#993300]Void[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#993300]if[/COLOR] [COLOR=#000000]([/COLOR]success[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#f000f0]*// Page title*[/COLOR]
pageTitle = [COLOR=#993300]this[/COLOR].[COLOR=#993300]firstChild[/COLOR].[COLOR=#993300]nextSibling[/COLOR].[COLOR=#993300]childNodes[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000000]0[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#993300]attributes[/COLOR].[COLOR=#000000]title[/COLOR];
[COLOR=#f000f0]*//Define the grid columns (in number of cells);*[/COLOR]
[COLOR=#993300]var[/COLOR] columns:[COLOR=#993300]Number[/COLOR] = [COLOR=#993300]int[/COLOR][COLOR=#000000]([/COLOR][COLOR=#993300]this[/COLOR].[COLOR=#993300]firstChild[/COLOR].[COLOR=#993300]nextSibling[/COLOR].[COLOR=#993300]childNodes[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000000]0[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#993300]attributes[/COLOR].[COLOR=#000000]columns[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#f000f0]*//Define the item vSpacing;*[/COLOR]
[COLOR=#993300]var[/COLOR] vSpacing:[COLOR=#993300]Number[/COLOR] = [COLOR=#993300]int[/COLOR][COLOR=#000000]([/COLOR][COLOR=#993300]this[/COLOR].[COLOR=#993300]firstChild[/COLOR].[COLOR=#993300]nextSibling[/COLOR].[COLOR=#993300]childNodes[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000000]0[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#993300]attributes[/COLOR].[COLOR=#000000]v_spacing[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#f000f0]*//Define the item hSpacing;*[/COLOR]
[COLOR=#993300]var[/COLOR] hSpacing:[COLOR=#993300]Number[/COLOR] = [COLOR=#993300]int[/COLOR][COLOR=#000000]([/COLOR][COLOR=#993300]this[/COLOR].[COLOR=#993300]firstChild[/COLOR].[COLOR=#993300]nextSibling[/COLOR].[COLOR=#993300]childNodes[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000000]0[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#993300]attributes[/COLOR].[COLOR=#000000]h_spacing[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#f000f0]*// define clips clicked*[/COLOR]
[COLOR=#993300]var[/COLOR] clickedClips = [COLOR=#000000]0[/COLOR];
[COLOR=#f000f0]*// define clicked clips array*[/COLOR]
[COLOR=#993300]var[/COLOR] clickedArray:[COLOR=#993300]Array[/COLOR] = [COLOR=#993300]new[/COLOR] [COLOR=#993300]Array[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#f000f0]*// define matching array*[/COLOR]
[COLOR=#993300]var[/COLOR] matchArray:[COLOR=#993300]Array[/COLOR] = [COLOR=#993300]new[/COLOR] [COLOR=#993300]Array[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#f000f0]*// correct items*[/COLOR]
[COLOR=#993300]var[/COLOR] correctAnswers = [COLOR=#000000]0[/COLOR];
[COLOR=#f000f0]*// var for number of matches*[/COLOR]
matchItems = [COLOR=#000000]([/COLOR][COLOR=#993300]this[/COLOR].[COLOR=#993300]firstChild[/COLOR].[COLOR=#993300]childNodes[/COLOR].[COLOR=#993300]length[/COLOR][COLOR=#000000])[/COLOR]/[COLOR=#000000]2[/COLOR];
[COLOR=#f000f0]*//Add each card*[/COLOR]
[COLOR=#993300]for[/COLOR] [COLOR=#000000]([/COLOR]i=[COLOR=#000000]0[/COLOR]; i<[COLOR=#000000]([/COLOR][COLOR=#993300]this[/COLOR].[COLOR=#993300]firstChild[/COLOR].[COLOR=#993300]childNodes[/COLOR].[COLOR=#993300]length[/COLOR][COLOR=#000000])[/COLOR]; i++[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#993300]var[/COLOR] attachProduct:[COLOR=#993300]MovieClip[/COLOR] = holder.[COLOR=#993300]attachMovie[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]"card_template"[/COLOR], [COLOR=#0000ff]"card_template"[/COLOR]+i, i[COLOR=#000000])[/COLOR];
[COLOR=#993300]trace[/COLOR][COLOR=#000000]([/COLOR]attachProduct[COLOR=#000000])[/COLOR];
[COLOR=#f000f0]*//********************[/COLOR]
[COLOR=#f000f0]*// get url of each image*[/COLOR]
imageUrl = [COLOR=#993300]this[/COLOR].[COLOR=#993300]firstChild[/COLOR].[COLOR=#993300]childNodes[/COLOR][COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#993300]attributes[/COLOR].[COLOR=#000000]src[/COLOR];
[COLOR=#f000f0]*//********************[/COLOR]
[COLOR=#f000f0]*//attach each image to each card*[/COLOR]
attachProduct.[COLOR=#000000]card_mc[/COLOR].[COLOR=#000000]graphic_holder[/COLOR].[COLOR=#000000]holder[/COLOR].[COLOR=#993300]loadMovie[/COLOR][COLOR=#000000]([/COLOR]imageUrl[COLOR=#000000])[/COLOR];
[COLOR=#f000f0]*//position the cards*[/COLOR]
attachProduct.[COLOR=#993300]_y[/COLOR] = [COLOR=#993300]Math[/COLOR].[COLOR=#993300]floor[/COLOR][COLOR=#000000]([/COLOR]i / columns[COLOR=#000000])[/COLOR] * [COLOR=#000000]([/COLOR]attachProduct.[COLOR=#993300]_height[/COLOR] + hSpacing[COLOR=#000000])[/COLOR];
attachProduct.[COLOR=#993300]_x[/COLOR] = [COLOR=#000000]([/COLOR]i % columns[COLOR=#000000])[/COLOR] * [COLOR=#000000]([/COLOR]attachProduct.[COLOR=#993300]_width[/COLOR] + vSpacing[COLOR=#000000])[/COLOR];
[COLOR=#f000f0]*//Image match Id*[/COLOR]
[COLOR=#993300]var[/COLOR] matchId = [COLOR=#0000ff]""[/COLOR];
attachProduct.[COLOR=#000000]matchId[/COLOR] = [COLOR=#993300]this[/COLOR].[COLOR=#993300]firstChild[/COLOR].[COLOR=#993300]childNodes[/COLOR][COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#993300]attributes[/COLOR].[COLOR=#000000]matchId[/COLOR];
[COLOR=#f000f0]*// Image title name*[/COLOR]
[COLOR=#993300]var[/COLOR] imageText = [COLOR=#0000ff]""[/COLOR];
imageText = [COLOR=#993300]this[/COLOR].[COLOR=#993300]firstChild[/COLOR].[COLOR=#993300]childNodes[/COLOR][COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#993300]attributes[/COLOR].[COLOR=#000000]title[/COLOR];
[COLOR=#f000f0]*//card button function*[/COLOR]
attachProduct.[COLOR=#000000]card_btn[/COLOR].[COLOR=#993300]onRelease[/COLOR] = [COLOR=#993300]function[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#993300]this[/COLOR].[COLOR=#993300]enabled[/COLOR] = [COLOR=#993300]false[/COLOR];
matchArray.[COLOR=#993300]push[/COLOR][COLOR=#000000]([/COLOR][COLOR=#993300]this[/COLOR].[COLOR=#993300]_parent[/COLOR].[COLOR=#000000]matchId[/COLOR][COLOR=#000000])[/COLOR];
clickedArray.[COLOR=#993300]push[/COLOR][COLOR=#000000]([/COLOR][COLOR=#993300]this[/COLOR].[COLOR=#993300]_parent[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#993300]this[/COLOR].[COLOR=#993300]_parent[/COLOR].[COLOR=#000000]card_mc[/COLOR].[COLOR=#993300]play[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
clickedClips += [COLOR=#000000]1[/COLOR];
[COLOR=#993300]this[/COLOR].[COLOR=#993300]_parent[/COLOR].[COLOR=#000000]card_mc[/COLOR].[COLOR=#993300]onEnterFrame[/COLOR] = [COLOR=#993300]function[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#993300]if[/COLOR][COLOR=#000000]([/COLOR]clickedClips == [COLOR=#000000]2[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#993300]_root[/COLOR].[COLOR=#000000]disableBtns[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#993300]if[/COLOR][COLOR=#000000]([/COLOR]clickedClips == [COLOR=#000000]2[/COLOR] && clickedArray[COLOR=#000000][[/COLOR][COLOR=#000000]1[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#000000]card_mc[/COLOR].[COLOR=#993300]_currentframe[/COLOR] == [COLOR=#000000]24[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#f000f0]*//trace("2 clips clicked!"); *[/COLOR]
[COLOR=#993300]_root[/COLOR].[COLOR=#000000]disableBtns[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#f000f0]*// check if the items match*[/COLOR]
[COLOR=#993300]if[/COLOR][COLOR=#000000]([/COLOR]matchArray[COLOR=#000000][[/COLOR][COLOR=#000000]0[/COLOR][COLOR=#000000]][/COLOR] == matchArray[COLOR=#000000][[/COLOR][COLOR=#000000]1[/COLOR][COLOR=#000000]][/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#f000f0]*//trace("they match!!");*[/COLOR]
fadeOut[COLOR=#000000]([/COLOR]clickedArray[COLOR=#000000][[/COLOR][COLOR=#000000]0[/COLOR][COLOR=#000000]][/COLOR], [COLOR=#000000]5[/COLOR], [COLOR=#000000]50[/COLOR][COLOR=#000000])[/COLOR];
fadeOut[COLOR=#000000]([/COLOR]clickedArray[COLOR=#000000][[/COLOR][COLOR=#000000]1[/COLOR][COLOR=#000000]][/COLOR], [COLOR=#000000]5[/COLOR], [COLOR=#000000]50[/COLOR][COLOR=#000000])[/COLOR];
clickedClips = [COLOR=#000000]0[/COLOR];
clickedArray = [COLOR=#000000][[/COLOR][COLOR=#000000]][/COLOR];
matchArray = [COLOR=#000000][[/COLOR][COLOR=#000000]][/COLOR];
correctAnswers += [COLOR=#000000]1[/COLOR];
[COLOR=#993300]_root[/COLOR].[COLOR=#000000]enableBtns[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#f000f0]*// if answers are correct play frame*[/COLOR]
[COLOR=#993300]if[/COLOR][COLOR=#000000]([/COLOR]correctAnswers == matchItems[COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#993300]_root[/COLOR].[COLOR=#993300]attachMovie[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]"excellent_mc"[/COLOR], [COLOR=#0000ff]"excellent_mc"[/COLOR], [COLOR=#993300]this[/COLOR].[COLOR=#993300]getNextHighestDepth[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#993300]_root[/COLOR].[COLOR=#000000]excellent_mc[/COLOR].[COLOR=#993300]_x[/COLOR] = [COLOR=#993300]Stage[/COLOR].[COLOR=#993300]width[/COLOR] / [COLOR=#000000]2[/COLOR];
[COLOR=#993300]_root[/COLOR].[COLOR=#000000]excellent_mc[/COLOR].[COLOR=#993300]_y[/COLOR] = [COLOR=#993300]Stage[/COLOR].[COLOR=#993300]height[/COLOR] / [COLOR=#000000]2[/COLOR];
[COLOR=#993300]var[/COLOR] xScale:Tween = [COLOR=#993300]new[/COLOR] Tween[COLOR=#000000]([/COLOR][COLOR=#993300]_root[/COLOR].[COLOR=#000000]excellent_mc[/COLOR], [COLOR=#0000ff]"_xScale"[/COLOR], Bounce.[COLOR=#000000]easeOut[/COLOR], [COLOR=#000000]40[/COLOR], [COLOR=#000000]100[/COLOR], [COLOR=#000000]1[/COLOR], [COLOR=#993300]true[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#993300]var[/COLOR] yScale:Tween = [COLOR=#993300]new[/COLOR] Tween[COLOR=#000000]([/COLOR][COLOR=#993300]_root[/COLOR].[COLOR=#000000]excellent_mc[/COLOR], [COLOR=#0000ff]"_yScale"[/COLOR], Bounce.[COLOR=#000000]easeOut[/COLOR], [COLOR=#000000]40[/COLOR], [COLOR=#000000]100[/COLOR], [COLOR=#000000]1[/COLOR], [COLOR=#993300]true[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR][COLOR=#993300]else[/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#f000f0]*//trace("Na mate!!");*[/COLOR]
clickedArray[COLOR=#000000][[/COLOR][COLOR=#000000]0[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#000000]card_mc[/COLOR].[COLOR=#000000]reverseShift[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]1000[/COLOR]/[COLOR=#000000]31[/COLOR], [COLOR=#000000]1[/COLOR][COLOR=#000000])[/COLOR];
clickedArray[COLOR=#000000][[/COLOR][COLOR=#000000]1[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#000000]card_mc[/COLOR].[COLOR=#000000]reverseShift[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]1000[/COLOR]/[COLOR=#000000]31[/COLOR], [COLOR=#000000]1[/COLOR][COLOR=#000000])[/COLOR];
clickedArray[COLOR=#000000][[/COLOR][COLOR=#000000]0[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#000000]card_btn[/COLOR].[COLOR=#993300]enabled[/COLOR] = [COLOR=#993300]true[/COLOR];
clickedArray[COLOR=#000000][[/COLOR][COLOR=#000000]1[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#000000]card_btn[/COLOR].[COLOR=#993300]enabled[/COLOR] = [COLOR=#993300]true[/COLOR];
clickedClips = [COLOR=#000000]0[/COLOR];
clickedArray = [COLOR=#000000][[/COLOR][COLOR=#000000]][/COLOR];
matchArray = [COLOR=#000000][[/COLOR][COLOR=#000000]][/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR] [COLOR=#993300]else[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#993300]trace[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]"Error loading XML data."[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR];
Cheers