A Flash Developer Resource Site














Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Featured Flash FLA
Gallery Downloads 11255 Flash Movies | 9 New Flash Movies Added
What's New | Top 100

Featured FLA

» Author: Knife Butterfly
» Title: SkullCandle
» Description: Simple Skull with a candle burning on it.
» More by Knife Butterfly


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 6392 Flash Sites | 0 New Flash Links
What's New | Top 100 Flash Site

Featured Site

» Posted in the Flash Kit Links section
» Title: Cesar Kobashikawa - online portfolio
» Comments: Cesar Kobashikawa's Portfolio


Random Links | Add your own Flash Related Links
Flash Tutorials 1201 Tutorials 7 New Tutorials Added!
What's New | Top100

» FLV Converter for Mac
» After Effects Quality Effect using AS3
» FLV to 3GP: Convert video files from FLV (Flash Video) to 3GP for Mac
» create Christmas business flash presentation with hyperlinks
» Let Photos Show Your Happy Family this Christmas and Upload YouTube
» PowerPoint show to DVD slide show--- PPS to DVD
» How to burn FLV to DVD for Mac
» How to Create Christmas Flash Greeting Ecard with photos and music
» Getting Started In Flash
» Unknown Tag: Title10
Random Tutorial | Add Site

bbm.netBBM.net is designed to save you time and deliver the highest quality royalty-free music for your multimedia projects. Features include: over 450 Music Loop Packages from some of the best composers in the business, our music search engine to speed your selection process, alternate music versions & bonus sounds to use for rollovers or transitions, free technical support and free consulting.

Click here for details »

Web Page Production
Aquent
US-MD-Owings Mills

Justtechjobs.com Post A Job | Post A Resume


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Categories FlashGuru's Array's Tutorial
Author: FlashGuru | Website: http://www.flashguru.co.uk |

 
Page 1
1 2 3 next»

FlashGuru's Arrays tutorial

If you are interested in arrays then i assume you already know about variables.
Variables are a container for one piece of data, this piece of data can be a number, a string or a boolean value.

Arrays are similar to variables as they too are containers for data, except that they can hold more than one piece of data, each element(piece of data) is referred to by an index.

Arrays can be used to keep your scripts more organised, they are usually used to group together multiple values that are in some way related to each other, the values use an index to distinguish them from each other. Suppose you wanted to write out 3 quotes for use in your movie and use variables for each quote, you could define 3 variables as follows:

quote1="Flash is cool!"
quote2="Flash is my favourite program"
quote3="Flash rules"

However a better way may be to use an array, there are numerous ways of creating an array but i will show you the easiest way first:

name_of_array=new Array()

So to store our quotes in an array we could use:

quotes=new Array()

Ok thats great we now have an array, but the problem is we dont have any data inside of our array, thats not very useful so we will now place data inside of our array, we do this by using an index number, the index number refers to the position in the array.

To place a piece of data inside the first element of our array we would use:

quotes[0]="Flash is cool!"

As i mentioned before, arrays in flash 5 are zero based, meaning that the first element in the array has an index of zero(0).

So to place a piece of data inside the second element of our array we would use:

quotes[1]="Flash is my favourite program"

We use this syntax to fill an element of an array with a piece of data:

name_of_array[index]=value

where name_of_array is the name of your array, the index is the position in your array and the value is the piece of data you want to add to your array.

So the code we created earlier using variables:

quote1="Flash is cool!"
quote2="Flash is my favourite program"
quote3="Flash rules"

can also be written as follows using arrays:

quotes=new Array()
quotes[0]="Flash is cool!"
quotes[1]="Flash is my favourite program"
quotes[2]="Flash rules"

Thats all great, but that is still alot of typing, we can also create an array of values using this syntax:

name_of_array=new Array("value1","value2","value3")

So basically the same as the code we wrote earlier, but in one long line of code, value1 will be the first element of your array, value2 the second element of your array and so on....

We could use the following code to create our array of quotes:

quotes=new Array("Flash is cool!","Flash is my favourite program","Flash rules")

Thats brilliant we now know how to create arrays and what they can be used for, but there is one more way of creating arrays that i want to make you aware of, the syntax is as follows:

name_of_array=["value1","value2","value3"]

Again similar to the previous syntax except that we didnt have to use the array object initilaizer(new Array())

So again we could create our array of quotes using the following code:

quotes=["Flash is cool!","Flash is my favourite program","Flash rules"]

The way you create arrays is entirely up to you but i prefer using the last synatx i showed you as it requires less typing.

Now we know how to create arrays, but you will at some point have to access the values of your array for use in your scripts. Well fortuneatley there is only one way of doing this and the synatx is as follows:

mynewvariable=name_of_array[index]

So lets say we want to get the value of the first element in our quotes array and place it in a new variable, we would use:

firstquote=quotes[0]

the new variable would be called firstquote and its value would be Flash is cool!

1 2 3 next»

» Level Intermediate

Added: : 2001-02-26
Rating: 7.93 Votes: 73
Hits: 3678
» Author
No details available
» Download
Download the files used in this tutorial.
Download (0 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments
 
   
 

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
  Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
MORE WHITEPAPERS, EBOOKS, AND ARTICLES