|
||||||
|
||||||
Using Flash to Load a Random Image

Free
Flash Tutorial
Step 3 << Previous • Intro 1 2
3 • >>
|
Step Three: Creating the ActionScript
Important Note: Make sure that you can see Actions - Frame at the top of the Actions Panel:
![]()
The Actions Panel has Actions - Frame in the top corner.
Note: To see if Script Assist is on or off go to the Action Panel's Side Menu Button:
![]()
Script Assist is On when ticked:
(remove the tick)
Cross Ref: If you are not sure what Script Assist is or how to switch it on and off see the short Tutorial: Actions Panel
// Sets the number of images in the random sequence
// IMPORTANT: Set this number to how many images you have
var myImageSequence = 25;// Creates a random number:
var myRandomNumber = Math.floor(Math.random()*myImageSequence)+1;// Creates the full image name like: 1.jpg
// IMPORTANT: If you're NOT using Jpegs change jpg to png or gif
var myImageName = myRandomNumber + ".jpg";// Loads the random image:
loadMovieNum(myImageName, 1);
Note: If your images are not the same size as your Flash Movie then the code above will align your images to the top left. If you would rather that your images were aligned to the center then change the load Movie Number from 1 to 0 like this:
loadMovieNum(myImageName, 0);
Note: This will load one image only. Just to check that the random load is working test your Movie several times in a row by repeatedly pressing: Ctrl Enter (You may see a blank Movie for a short while when waiting for the next image to load, this is just like refreshing you browser and is normal. If you don't wish to wait press Ctrl Enter twice in a row).
Important: In test mode if you have not saved your Flash file into the same folder as your images your movie will not work. When you upload your files to the Internet then the HTML page must be in the same location as the images and the location of the Flash Movie becomes irrelevant. If you want to use your Flash file in multiple web pages and load images form one location you will need to specify an absolute address like this:
var myImageName = "http://www.yourwebsite.com/images/" + myRandomNumber + ".jpg";
I hope you have found this useful. If so perhaps you could recommend this site to others and link to webwasp!
|
<< Previous 1 2 3 4 5 Next >> |
Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates
•
11102 visitors to this page since
26 Oct 07 •
|
|
|
All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.
|