Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Call Random Pictures

I'm trying to create an app that each time someone want to go to a new picture, it calls up a random one so that each time they are in the app, it is a different experience.

Does anyone know of any sample code for this to work?

— asked October 12th 2010 by J W
  • images
  • iphone
  • random
0 Comments

2 Answers

  • Create it yourself, it shouldn't be hard. Use filesystem to get the names of the image files, then randomly select them using rand or some other method.

    — answered October 12th 2010 by Eddie Monge
    permalink
    1 Comment
    • Sorry I am new to this and any example that you could point me to that shows this would be very beneficial

      — commented October 12th 2010 by J W
  • Just download this function:

    http://phpjs.org/functions/rand:498

    Call your images 0.png 1.png 2.png etc

    Then use something like this:

    var rondomnumber = rand(0,(20-1)); //change 20 to the amount of images you have
    var tabs3 = Titanium.UI.createButton( //or something else then a button...
    {
    backgroundImage: randomnumber+'.png'
    }
    
    — answered October 13th 2010 by Peter Griffin
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.