• Home
  • Free Tutorials
  • Free Video Tutorials

Adobe Photoshop
Autodesk 3ds Max
CSS
Flash
Help Center Live
iPhone
Joomla
Make Money Online!
Mambo
mIRC
Outlook Express
SEO / SEM
Simple Machine Forum
Target Explorer

Random Pattern Background

Category : Flash Views : 30482
Version : 8 Rating : 
3.1/5 (32 votes)
  • Currently 3.09/5
  • 1
  • 2
  • 3
  • 4
  • 5
Type : Text Source File: random-pattern-background.zip
Result: See the result


Previous | 1 | 2 | Next

The result will be different.
Free Flash Tutorials, Actionscript, Random Pattern Background

Code Explanation

import flash.display.BitmapData
This line of code imports the BitmapData library to our code so we can create a BitmapData object to hold our image

var patNr = 4;
The number of patterns we have available to load.

nPattern.onRelease = function() {
Event for when the user clicks the pattern button.

var img = "pat" + Math.ceil(Math.random() * patNr);
Variable to use as identifier when we load the image from the library; the variable will be "pat" plus a random number between 1 and patNr.
Because "Math.random() * patNr" would return a number between 0 and patNr and I don't have a pattern with the identifier "pat0" I need to round up the random number so I never get 0. For that we use the following function:
Math.ceil(number);
This function will always round a floating point up.

_root.createEmptyMovieClip("holder", 1);
Create a new Movie Clip to place a pattern.

var imgBitmap = BitmapData.loadBitmap(img);
This variable is a Bitmap object created with the function loadBitmap(identifier), this function will load a bitmap from the library using the identifier.

holder.clear();
Erase any previous pattern on the Movie Clip.

holder.beginBitmapFill(imgBitmap);
Start filling the Movie Clip with the pattern bitmap.

holder.lineTo(550, 0); holder.lineTo(550, 400); holder.lineTo(0, 400); holder.lineTo(0, 0);
Draw around the stage to make the pattern fill everything.

holder.endFill();
Stop filling the bitmap.

nPattern.swapDepths(33);
Swap the depth of the button so it always stays on top of the pattern and the user can see it.


del.icio.us digg it Reddit Stumble Upon Technorati

Previous | 1 | 2 | Next
How to Video Tutorials on software by Helpvids.com

Video tutorial: Forex trading



Sponsors



Advertisement









Studio | Advertisement | About Webzo | Contact Webzo | Terms of Use | Free Video Tutorials by Helpivds

Copyright © 2007 NR Concepts Ltd. All rights reserved.