I have seen many questions concerning randomly selecting array items without repeating. However, most of them are answered by using the splice method. But this removes items.
I have already selected my items randomly, but they are repeating. In my two functions I select from each randomly selected item two "sub-items". The two functions are not working together, I am looking for a way that it is possible to select two different randomly selected items, without repetition, and without removing them. Can one please help me out?
(Using Adobe Edge Animate)
var xml_source = "series.xml";
var initLoadScript = false;
var items = [];
var itemTitle1;
var obj = new Object();
var previousNumber = -1;
loadXML();
function loadXML() {
$.ajax({
type: "GET",
url: xml_source,
dataType: "xml",
success: function(xml) {
$(xml).find('sbs').find('channel').find('item').each(function() {
items.push($(this));
});
itemOne();
itemTwo();
}
});
}
function itemOne(){
var randomNumber = Math.floor(Math.random()*14);
var assignItem = randomNumber;
console.log("random nummer 1: " + assignItem);
sym.$("TitleText1").html(items[assignItem].find("author_name").text());
sym.$("Image1").html("<img src='"+items[assignItem].find('media\\:content, content').find('media\\:thumbnail, thumbnail').attr('url')+"' width='145'/>");
}
function itemTwo(){
var randomNumber = Math.floor(Math.random()*14);
var assignItem = randomNumber;
console.log("random nummer 2: " + assignItem);
sym.$("TitleText2").html(items[assignItem].find("author_name").text());
sym.$("Image2").html("<img src='"+items[assignItem].find('media\\:content, content').find('media\\:thumbnail, thumbnail').attr('url')+"' width='145'/>");
}
Aucun commentaire:
Enregistrer un commentaire