OOPS...thank goodness I re-read my last post... realized I screwed up,
because the first version I made should actually modify your original
xml. Wow, sometimes I wish this was like a web Forum and you could
just click edit.
I had used XMLList, when it should have been new XML, and you should be
sending in the imgList.IMAGE list section. As well, in addition the
quick fix, I updated the code to show the different method that makes a
randomized Typed Array (otherwise known as a vector) that points to the
index locations in the original xml. Don't hesitate to tell me if I
screwed up again.
//Updated examplevar ss:XML =<SLIDESHOW SPEED="2"><IMAGE
SRC="images1.jpg" DESC="Rome"/>
<IMAGE SRC="images2.jpg" DESC="Paris"/>
<IMAGE SRC="images3.jpg" DESC="Cairo"/>
<IMAGE SRC="images4.jpg" DESC="London"/>
<IMAGE SRC="images5.jpg" DESC="New Yor City"/>
<IMAGE SRC="images6.jpg" DESC="Paris"/>
<IMAGE SRC="images7.jpg" DESC="Tokyo"/>
<IMAGE SRC="images8.jpg" DESC="Toronto"/>
<IMAGE SRC="images9.jpg" DESC="Nepal"/>
<IMAGE SRC="images10.jpg" DESC="Venice"/>
<IMAGE SRC="images11.jpg" DESC="what"/>
<IMAGE SRC="images12.jpg" DESC="ever"/>
<IMAGE SRC="images13.jpg" DESC="you"/>
<IMAGE SRC="images14.jpg" DESC="get"/>
<IMAGE SRC="images15.jpg" DESC="the"/>
<IMAGE SRC="images16.jpg" DESC="idea"/>
</SLIDESHOW>;
var imgList:XML = new XML(ss);
function randXMLList(xl:XMLList):void{
var sn:int;//swap number
var xh:XML;//temp xml holder
var i:int=0;
var l:int = xl.length();
while(i!=l){
sn = Math.floor(Math.random() *l);
xh = xl[i];
xl[i] = xl[sn];
xl[sn] = xh;
++i;
}
}
randXMLList(imgList.IMAGE);
trace('............original xml...........\n'+ss.IMAGE+'\n\n');
trace('..........New Modified xml.........\n'+imgList.IMAGE+'\n\n');
//different method
var l:int = ss.IMAGE.length();
var randi:Vector.<int>=new Vector.<int>(l,true);//random array for index
values
var tv:int;//temp value
var sn:int;//swap number
for(var i:int = 0; i!=l;++i){
randi[i]=i;
}
trace('...original order...\n'+randi+'\n');
for(i=0;i!=l;++i){
sn = Math.floor(Math.random()*l);
tv = randi[sn];
randi[sn] = randi[i];
randi[i] = tv;
}
trace('...modified order...\n'+randi+'\n\n...IMAGE SRC values...');
//example of how to make use of it
for(i=0;i!=l;++i){
trace(ss.IMAGE[randi[i]].@SRC);
}
On 1/22/2011 4:41 PM, Anthony Pace wrote:
Sorry I took so long. I had no internet at home for that past couple
of days.
...Well, you don't really have to make it an array. I guess I should
have said, use it like you would an array.
Since it seems you want to know how to keep the original order and
have a new list with a randomized order,for ease of use, I figured you
might want an XMLList, so I made the example below.
//there is another way without duplicating data in memory, but I
figure this might be easy to work with.
var ss:XML =<SLIDESHOW SPEED="2"><IMAGE SRC="images1.jpg" DESC="Rome"/>
<IMAGE SRC="images2.jpg" DESC="Paris"/>
<IMAGE SRC="images3.jpg" DESC="Cairo"/>
<IMAGE SRC="images4.jpg" DESC="London"/>
<IMAGE SRC="images5.jpg" DESC="New Yor City"/>
<IMAGE SRC="images6.jpg" DESC="Paris"/>
<IMAGE SRC="images7.jpg" DESC="Tokyo"/>
<IMAGE SRC="images8.jpg" DESC="Toronto"/>
<IMAGE SRC="images9.jpg" DESC="Nepal"/>
<IMAGE SRC="images10.jpg" DESC="Venice"/>
<IMAGE SRC="images11.jpg" DESC="what"/>
<IMAGE SRC="images12.jpg" DESC="ever"/>
<IMAGE SRC="images13.jpg" DESC="you"/>
<IMAGE SRC="images14.jpg" DESC="get"/>
<IMAGE SRC="images15.jpg" DESC="the"/>
<IMAGE SRC="images16.jpg" DESC="idea"/>
</SLIDESHOW>;
var imgList:XMLList = ss.IMAGE;
function randXMLList(xl:XMLList):void{
var sn:int;//swap number
var xh:XML;//temp xml holder
var i:int=0;
var l:int = xl.length();
while(i!=l){
sn = Math.floor(Math.random() *l);
xh = xl[i];
xl[i] = xl[sn];
xl[sn] = xh;
++i;
}
}
randXMLList(imgList);
trace(imgList);
On 1/21/2011 3:47 PM, Christopher Lucas wrote:
Anthony, Thanks for your response. I conceptually understand Arrays, but
really am lost in how they work with AS3. Any change you might be
willing to
show me how this would be done?
Won't the image and corresponding desc both be scrambled in an array
since I
want to display them together?
Thanks
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders