Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I set else for both and

Posted on 2011-02-19
3
Medium Priority
?
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
andreizz earned 2000 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
Suggested Courses

664 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