Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Random Quotes - Page 3

November 27, 2001



One of the features that I have on my own Web site (www.webryder.com) that gets quite a bit of comments is the random quotes shown above. It adds some originality to the site. I am going to give you the code that is used to create it so that we can all enjoy it.

It is really straight forward and can be set-up quickly. To begin, start a new Flash file. On the very first frame of the file define the quotes you are going to use on the site, using an array to store the variables. You may want to have it on a layer called "Actions" to keep things a little better organized. Also note that the "//" simply precedes a comment about the function. The number of quotes is defined by the total quotes we are going to use. Remember that the array actually starts with zero ("0") and not one ("1"). Click on the first keyframe of the movie and input the following script using the Frame Actions that is available.

// It is up to you how you stick the quotes into the array
numQuotes = 17;
quoteArray = new Array();
quoteArray[0] = "'Give me a museum and I'll fill it.'
  - Pablo Picasso";
quoteArray[1] = "'While we are postponing, life speeds by.'
  - Seneca";
quoteArray[2] = "'We didn't lose the game; we just ran out of
  time.' - Vince Lombardi";
quoteArray[3] = "'Knowledge speaks, but wisdom listens.'
  - Jimi Hendrix";
quoteArray[4] = "'Make everything as simple as possible, but
  not simpler.' - Albert Einstein";
quoteArray[5] = "'Forgive your enemies, but never forget their
  names.' - John F. Kennedy";
quoteArray[6] = "'I don't know anything about music. In my
  line you don't have to.' - Elvis Presley";
quoteArray[7] = "'The cynics are right nine times out of ten.'
  - Henry Louis Mencken";
quoteArray[8] = "'I would have made a good Pope.' - Richard
  M. Nixon ";
quoteArray[9] = "'It is dangerous to be sincere unless you
  are also stupid'. - George Bernard Shaw ";
quoteArray[10] = "'A man can't be too careful in the choice
  of his enemies. '- Oscar Wilde ";
quoteArray[11] = "'Logic is in the eye of the logician.'
  - Gloria Steinem ";
quoteArray[12] = "'Everything has been figured out, except
  how to live.' - Jean-Paul Sartre ";
quoteArray[13] = "'In the end, everything is a gag.'- Charlie
  Chaplin ";
quoteArray[14] = "'He who hesitates is a damned fool. '- Mae
  West ";
quoteArray[15] = "'Behind every great fortune there is a
  crime. '- Honore de Balzac ";
quoteArray[16] = "'I am not young enough to know everything.'
  - Oscar Wilde ";
// A dynamic textbox variable to display the text....
QuoteText = quoteArray[Math.floor(Math.random()*numQuotes)];

The very last part of the function is to pick a random number which is defined as a pseudo-random number between 0.0 and 1.0. Then it multiples that result by the numQuotes variable. In this example the number is 17. Using the Math.floor function it then takes the result and turns it into the closest integer. From here it simply takes the corresponding array number and stores inside of the QuoteText variable, so that this can be viewed in Flash file as the quote.

Next we want to set up a location for the quote to be viewed. It isn't enough to simply define all of the variables and generate a random quote, but it needs to be shown as well.

However, this is really easy to do! You simply use the text box tool to draw a box across the stage of the movie big enough to display all of the text for the quotes. You will also want to change the font properties so that it fits nicely on the screen. The most important aspect of the text box is to make sure that it is designated as "dynamic text". (If you don't want visitors to be able to copy the quotes, make sure the "selectable" option is turned off. In the variable name option put in QuoteText. This is where the quote will now be displayed. Simply publish the Flash file and view the results! In order to publish the file and html code, simply choose "File > Publish" from the menu options or select [SHIFT]+[F12] on the keyboard.

The techniques learned here can help to create other applications. You can use the date variables to display personal messages or games that blow up spaceships. The random quote example could be changed to have random numbers selected, then certain events occur based on the number chosen.

If you have any suggestions on Flash topics that you would like to see covered in the future, please feel free to contact me at sryder@webryder.com.

Colliding Clips - Page 2
Flash 5 Tutorial: Part 1
Cursors, and Text, and HTML.... Oh My!


Up to => Home / Authoring / Flash / Basic




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers