« Home « Kết quả tìm kiếm

Creating Arrays


Tóm tắt Xem thử

- Think of arrays as supervariables: While a regular variable can only contain a single value, an array can contain multiple values—which means you could store that entire guest list in a single array..
- However, you must create an array in order to use it.
- Here's the syntax to create an array:.
- var myArray:Array = new Array();.
- You can populate an array with values separated by commas when you create it, like this:.
- var guestList:Array = new Array("John Smith","Kelly McAvoy","Joyce Rendir","Tripp Carter");.
- Each value in an array is identified by an index number—0, 1, 2, and so on—that denotes its position in the array.
- An array element can contain any data type, including strings, numbers, and Boolean values, as well as entire objects.
- An array element can even contain another array.
- You'll learn more about arrays and methods of the Array class in later lessons.
- exercise—in which you'll use arrays to store groups of related information for each day of the week—represents just the beginning..
- You cannot use the var syntax when you're creating an array on an object unless you're building your own custom class of objects.
- "Creating Custom Classes.".
- With newsFlash2.fla still open, select Frame 1 of the Actions layer.
- Add this script after the monday.date = "Monday, August .
- monday.weather = new Array();.
- monday.weather[0.
- monday.weather[1.
- monday.weather[2.
- monday.weather[3.
- You created an array called weather that's used to store weather data.
- The array is on the object monday.
- The value of the first element (the 0th index) of the weather array will be used later to send this movie clip instance to the correct frame.
- The second element of the weather array contains a blurb about Monday's weather, which will be.
- displayed later on the screen..
- The high and low temperatures for Monday are stored in the third and fourth elements of the weather array, respectively.
- These values will be accessed later so that they can be displayed on the news page..
- You have just created an array that stores four pieces of related information in a way that is easily accessible..
- With Frame 1 still selected, insert this script after tuesday.date = "Tuesday, August .
- tuesday.weather = new Array();.
- tuesday.weather[0.
- tuesday.weather[1.
- tuesday.weather[2.
- tuesday.weather[3.
- You have created another array named weather, but this array is on the tuesday object.
- The value of each array element here is different from that of the weather array for Monday, but the index numbers of corresponding values are the same: although the high temperatures for Monday and Tuesday are different, they're both stored at the Number 2 index position in each array..
- Create arrays to contain news articles for individual categories by entering this script after monday.weather[3.
- monday.entertainment = new Array();.
- monday.entertainment[0.
- monday.entertainment[1.
- monday.entertainment[2.
- monday.politics = new Array();.
- monday.politics[0.
- monday.politics[1.
- "Candidates are preparing for a year-long campaign...";.
- monday.politics[2.
- monday.sports = new Array();.
- monday.sports[0.
- monday.sports[1.
- "The Head Atlantis tennis racquet is one of the most popular racquets.
- in history...";.
- monday.sports[2.
- monday.technology = new Array();.
- monday.technology[0.
- monday.technology[1.
- than light...";.
- monday.technology[2.
- This news site can display four sections of stories: entertainment, politics, sports, and technology, as indicated by the navigation buttons on the left of the screen..
- For each of these sections, we created an array and stored information about one article for that Monday.
- In the first section of this step, we created an array called entertainment.
- The first element of the entertainment array stores the news story's headline.
- element stores the name of the author.
- Add this news article script after tuesday.weather[3.
- tuesday.entertainment = new Array();.
- tuesday.entertainment[0.
- tuesday.entertainment[1.
- "Sentrillion Blazers is the must see sci-fi movie of the year!...";.
- tuesday.entertainment[2.
- tuesday.politics = new Array();.
- tuesday.politics[0.
- tuesday.politics[1.
- "School systems protest the yearly testing criteria...";.
- tuesday.politics[2.
- tuesday.sports = new Array();.
- tuesday.sports[0.
- tuesday.sports[1.
- tuesday.sports[2.
- tuesday.technology = new Array();.
- tuesday.technology[0.
- tuesday.technology[1.
- the BajillaHertz chip...";.
- tuesday.technology[2.
- Because all of the script we created so far is placed on Frame 1, this data will be created as soon as the movie begins to play

Xem thử không khả dụng, vui lòng xem tại trang nguồn
hoặc xem Tóm tắt