Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Sorting XML content

From: Creating a Portfolio Web Site Using Flash CS4 Professional

Video: Sorting XML content

Once the XML is loaded in Flash, you can start to sort through the content to determine what you want to use. So as you can see, it's really currently just a big dump of the XML, verbatim everything that's in the XML file. I want to start sorting through these individual items to start accessing their content. So I'm going to go to the Timeline to that very first frame in the AS layer and I am going to go to window to open up my Actions panel. Notice at the top, here is why I load in the XML, defines what file it is and once it's completed loading, it traces out all of the data.

Sorting XML content

Once the XML is loaded in Flash, you can start to sort through the content to determine what you want to use. So as you can see, it's really currently just a big dump of the XML, verbatim everything that's in the XML file. I want to start sorting through these individual items to start accessing their content. So I'm going to go to the Timeline to that very first frame in the AS layer and I am going to go to window to open up my Actions panel. Notice at the top, here is why I load in the XML, defines what file it is and once it's completed loading, it traces out all of the data.

Okay, so that's where that big dump of data comes from. It comes from this. But what I want to do is start tracing out the individual items. So before this closing curly brace, I want to create a new variable. In fact, I am just going to delete this information because I'm going to create a new variable and it's going to be called theXMLData and it's going to be an XML file and it's going to be equal to new XML. And then within these parentheses is that data.

So that's why I just deleted the trace statement. So what I want to do is take all of the content in here and put it right in this variable called theXMLData. Now that all the data is in there, I can start tracing out some of it. So I am just going to type in 'trace (length,' because the first thing I want to get is the length of this XML. So the length, colon, and that's in quotes and I can add Plus and I can start to type in theXMLData and I want to actually get the title.length.

Length is a property available to the XML class. So again, that's why I've created this new XML, because I can start accessing things like the length. So that's what's going to be displayed when I run this code. It's going to trace out the length, but I am going to type in a couple more things in here. I am going to type in another trace statement and instead of the length, I am going to get the title, the actual title, and I am going to go ahead and use this information right here. So I am just going to copy it and paste it right here.

So what's happening right now is it's going to get the title information but what node in the lineup of the title am I going to get? So am I going to get the first item, the last item? Because they're all numbered. There's about 12 titles in there, because there's 12 different portfolio pieces. So what I need to do is I need to type in title and I need to reference a number. So I am going to do brackets and within those brackets, I'm just going to type zero. Now that's going to get the title of the very first item, starting at zero, and make sure I close that parentheses, just like that, and I want to do the same thing.

In fact, I am going to copy this, Command+C, Command+V and I am going to start getting more of the information. So Description and theXMLData I am going to change title to Description, just like that. So it's going to get the description of the very first item. Again, I am going to paste in that code again, and I am going to get the large image. That's going to be the large image name, and instead of the title or description, it's going to be largeImage. And lastly, I am going to go ahead and do the thumbnail and I am going to change this title to thumbImage.

Now I need to make sure these various items exist within the XML. These are the various tags that I've defined, but these do match up and what I am going to do is I am just going to go ahead and run this code. First off, I'll do the check syntax and it does say it contains some errors. So I am going to go ahead and take a look at some of that, and for this one, theXMLData.title.length, it's giving me an error, and it's probably that semicolon there.

So I am just going to go ahead and hit Check Syntax and then that gets rid of the error. So it's looking good now. Let's do a Test Movie. It runs. I am just going to just close this because I want to close my Actions panel as well and peek into the Output panel. So notice that it does get the length, so it says that there's 12 items and then it gets the very first information of the very first node, which is actually Node 0, but it gets the title of it. It gets the description.

It gets the large image path and the thumbnail. So it doesn't show me any of the various tags. It just shows me the content within the tags, and as you can tell, this information here is much more useful for me. So what I want to do is I want to get the other data as well. So I am going to open up the Actions panel. Now what I want to do is I am going to create a loop because I want to loop through all of this and I want to show all of the content for all of the various nodes. So for these trace statements, I am going to type in a for. I am going to create a for loop and I am going to make i equal to a number.

It's going to be a Number and that's going to be equal to zero. It's going to start at the zero node and it's going to loop through this data. And then I am going to type in i. As long as i is less than the total length of this XML information, then keep on running through the code. So I am just going to copy this code and paste it up here. So this code is really going to execute multiple times. So this is where we do a comparison to see if i is less than the total length of this information.

And lastly, I need to type i and then do Plus, Plus. So what that does is it adds one each time this code is executed. But I need to make sure I finish writing this code because I need to do an open curly brace and then a closing curly brace. And I encourage you to, each time you add these curly braces, you write a function or anything, go ahead and check this Autoformat button and it will go ahead and nest all of those trace statements. Now I can see what's in the for loop.

So it's going to run through all of this information, starting at zero. It's going to do it for the length of the array and each time it loops through, it's just going to go ahead and add 1 to i. Now I don't want it to keep sort of printing out in the Output panel the item that's in the first position. I want it to change each time. So I am going to replace these zeros with an i, because what i is is it becomes zero the first time through, then it adds one. Then it becomes 1 the second time through and then becomes 2 the third time through, and it does that 12 times.

So if I just reset this back to i and I check my syntax, it does say that it doesn't have any errors and I am going to do a Test Movie. Close that SWF file. I am going to close my Actions panel and as I look at this information, I can see that all of the data is in there, none of the tags, but just the raw information that I want to take and use in my Flash file is all there and quite frankly, it's ready to be used. So through the code I have just written, I am able to access this information and then the next step, obviously, would be to use it in my Flash file.

Show transcript

This video is part of

Image for Creating a Portfolio Web Site Using Flash CS4 Professional
 
Expand all | Collapse all
  1. 1m 41s
    1. Welcome
      1m 7s
    2. Using the exercise files
      34s
  2. 24m 1s
    1. Understanding web design
      2m 44s
    2. Creating a Flash file
      3m 18s
    3. Importing a design from Photoshop
      7m 45s
    4. Optimizing the design
      10m 14s
  3. 13m 59s
    1. Dynamically loading an image
      3m 37s
    2. Loading random images
      10m 22s
  4. 47m 38s
    1. Creating menu buttons
      8m 18s
    2. Adding functionality to buttons
      8m 56s
    3. Adding navigation
      9m 45s
    4. Creating transitions
      12m 0s
    5. Simplifying code
      8m 39s
  5. 26m 11s
    1. Creating web site sections
      7m 41s
    2. Dynamically loading sections
      11m 7s
    3. Linking to web sites and email addresses
      7m 23s
  6. 29m 18s
    1. Setting up a portfolio
      12m 31s
    2. Adding functionality to thumbnails
      10m 10s
    3. Allowing for unlimited thumbnails
      6m 37s
  7. 41m 17s
    1. Benefits of using XML
      4m 42s
    2. Loading XML content
      4m 34s
    3. Sorting XML content
      7m 32s
    4. Displaying XML content
      7m 35s
    5. Using XML to create thumbnails
      8m 41s
    6. Displaying content with thumbnails
      8m 13s
  8. 25m 59s
    1. Creating and importing video
      9m 47s
    2. Adding a Full Screen button
      4m 15s
    3. Creating custom video controls
      4m 50s
    4. Adding functionality to video thumbnails
      7m 7s
  9. 9m 12s
    1. Adding audio to buttons
      5m 30s
    2. Adding audio to dynamically created buttons
      3m 42s
  10. 21m 19s
    1. Applying professional transitions
      9m 26s
    2. Creating a preloader
      8m 56s
    3. Publishing a web site
      2m 57s
  11. 3m 15s
    1. Reviewing the "corporate" Flash site
      1m 40s
    2. Reviewing the "artistic" Flash site
      1m 35s
  12. 12s
    1. Goodbye
      12s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Creating a Portfolio Web Site Using Flash CS4 Professional.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.