Solved

How do I set else for both and

Posted on 2011-02-19
3
277 Views
Last Modified: 2012-05-11
I have a situation where I am iterating a xml-string, with several id-nodes.
If one of the id-nodes equals a predefined number, the movie should show solution A, but if the predefined number does not exist as an id-node, it should show solution B.

The problem is that if I iterate the xml, both scenarios exist, if I compare IDs.
It equals an ID and it does not equals an ID.
Take a look:
var bookLength=myXML.Book;
for (var i:int; i < bookLength.length(); i++ ) {
if (myXML.Book[i].id==0684826976){
title_TF.x=30;
}
else{
title_TF.x=50;
}
}

Open in new window

The problem is that title_TF will show in both positions since both situations are correct.
But obviously I only want one of the solutions to show.


<Books>
 <Book>
  <id>0553212419</id>
  <title>Sherlock Holmes: Complete Novels and Stories, Vol 1</title>
  <author>Sir Arthur Conan Doyle</author>
</Book>
<Book>
  <id>0743273567</id>
  <title>The Great Gatsby</title>
  <author>F. Scott Fitzgerald</author>
</Book>
<Books>
 <Book>
  <id>0684826976</id>
  <title>Undaunted Courage</title>
  <author>Stephen E. Ambrose</author>
</Book>
<Book>
  <id>0743203178</id>
  <title>Nothing Like It In the World</title>
  <author>Stephen E. Ambrose</author>
 </Book>
</Books>

Open in new window

0
Comment
Question by:petersego
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
andreizz earned 500 total points
ID: 34933468
var bookLength=myXML.Book;
for (var i:int; i < bookLength.length(); i++ ) {
if (myXML.Book[i].id==0684826976){
title_TF.x=30; break;
}
else{
title_TF.x=50; break;
}
}

Open in new window


the break; command will exit the for after one executed path
0
 

Author Closing Comment

by:petersego
ID: 34933547
Ahh, brillant, Thanks alot.
0
 
LVL 4

Expert Comment

by:andreizz
ID: 34933551
No problem, good luck!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now