Gaz Smith
Gaz Smith

Reputation: 1108

AS3 and XML Filtering by time

I have some XML that i am pulling into flash with AS3.

This is the XML that is loaded into the flash :

               <Flights>
  <flight>
    <number>GS1234</number>
    <date>10/11/2015</date>
    <time>1440</time>
  </flight>
  <flight>
    <number>TD1234</number>
    <date>10/11/2015</date>
    <time>1450</time>
  </flight>
  <flight>
    <number>DDS342</number>
    <date>11/11/2015</date>
    <time>1540</time>
  </flight>
  <flight>
    <number>EJ8888</number>
    <date>11/11/2015</date>
    <time>1550</time>
  </flight>
  <flight>
    <number>DEV666</number>
    <date>12/11/2015</date>
    <time>1600</time>
  </flight>
</Flights>

What i need to do is filter this but by time, an hour ahead of a given time.

So if i enter the time 14:20, it will return all the flights that are within the time range of 14:20 and 15:20.

Is this possible any easier than putting everything into an array and looping through?

Upvotes: 0

Views: 35

Answers (1)

Aaron Beall
Aaron Beall

Reputation: 52183

You don't have to convert to an array. You can use e4x filtering, and since your times are formatted as a number its a simple numeric comparison:

var departing:XMLList = xml.flight.(time > 1420 && time < 1520);

Gives you:

<flight>
  <number>GS1234</number>
  <date>10/11/2015</date>
  <time>1440</time>     </flight>
 <flight>
  <number>TD1234</number>
  <date>10/11/2015</date>
  <time>1450</time>
</flight>

Upvotes: 4

Related Questions