displaying random images

  • Halo
  • Novice
  • Novice
  • User avatar
  • Posts: 19
  • Loc: Middle of nowhere

Post 3+ Months Ago

Hi, I am trying to figure out a way to display a single random image from my library when i enter a frame.


Anyone got any ideas?

Thanks.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • RedBMedia
  • Proficient
  • Proficient
  • User avatar
  • Posts: 315

Post 3+ Months Ago

Matt Mullenweg, the creator of WordPress once wrote a great little script that pulls up random images. check it out with the link below.

http://ma.tt/scripts/randomimage/
  • Jenie0109
  • Proficient
  • Proficient
  • User avatar
  • Posts: 410

Post 3+ Months Ago

This is just so cool.
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

well since no one actually answered the question about Flash I'll take a stab at it.

You need to make your images into movieclips (they don't have to be on the stage) and then make sure each movieclip has a linkage ID in the library (right click on the library item -> linkage). Next you need to write some actionscript. Create a blank keyframe on your timeline, select it and open your script window.

First you need to make an array or all the linkage ID's you created in the library. So:
Code: [ Select ]
var imgList:Array = ["linkageID1","linkageID2","linkageID3"];


next you want to get a random number between 0 and the total number of items in the array so:
Code: [ Select ]
var randImage = Math.floor(Math.random()*(imgList.length - 1));


finally you need to attach the chosen image to the stage:
Code: [ Select ]
var attachedImg = attachMovie(randImage,_root.getNextHighestDepth());
There you go thats pretty much all there is to it. So your final code would look like:

Code: [ Select ]
var imgList:Array = ["linkageID1","linkageID2","linkageID3"];
var randImage = Math.floor(Math.random()*(imgList.length - 1));
var attachedImg = attachMovie(randImage,_root.getNextHighestDepth());
  1. var imgList:Array = ["linkageID1","linkageID2","linkageID3"];
  2. var randImage = Math.floor(Math.random()*(imgList.length - 1));
  3. var attachedImg = attachMovie(randImage,_root.getNextHighestDepth());

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 24 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.