Link to home
Start Free TrialLog in
Avatar of VeyronSA
VeyronSA

asked on

Flash/Flex change xml data according to time

Hi All,

Busy with a project, but need help to compile a flash/flex component to change data got from XML according to time.

Here is my XML sample:
<?xml version="1.0"?>
<catalog>
   <dj id="00h00>
      <onair>Gambardella, Matthew</onair>
      <showname>Grave Shift</showname>
      <image>http://www.domain.com/app/images/matthew.png</image>
      <blog>http://www.domain.com/blog/mattheew</blog>
      <email>matthew@domain.com</email>
   </dj>
   <dj id="03h00>
      <onair>Delport, Mardi</onair>
      <showname>After Night</showname>
      <image>http://www.domain.com/app/images/mardi.png</image>
      <blog>http://www.domain.com/blog/mardi</blog>
      <email>mardi@domain.com</email>
   </dj>
</catalog>

Open in new window


What i need is a way to display the details according to different times (radio station). When on certain time, the component change the data gotten from XML document.

Please help :)
Avatar of petiex
petiex
Flag of United States of America image

You can build a string like the ones you have in the dj id value from the current date object, and then, since alphabetical order and time order are the same in this case, the first dj time slot that is in the past will be the active one:
private function chooseDJ(x:XML):XML{
            var date:Date = new Date();
            var nowH:int = date.getHours();
            var nowM:int = date.getMinutes();
            var activeDj:XML = null;
            var nowStr:String = (nowH > 9?"":"0")+nowH+"h"+(nowM > 9?"":"0")+nowM;
            for each (var dj:XML in x.dj){
                if(dj.id < nowStr){
                    activeDj = dj;
                    break;
                }
            }
            return activeDj;
        }

Open in new window

Then, of course, if the current time is earlier than the earliest time slot, you cycle through the dj xmls to get the latest timeslot...


private function chooseDJ(x:XML):XML{
            var date:Date = new Date();
            var nowH:int = date.getHours();
            var nowM:int = date.getMinutes();
            var activeDj:XML = null;
            var latestSlot:XML = null;
            var nowStr:String = (nowH > 9?"":"0")+nowH+"h"+(nowM > 9?"":"0")+nowM;
            for each (var dj:XML in x.dj){
                if(!latestSlot || latestSlot.id < dj.id){
                    latestSlot = dj;
                }
                if(dj.id < nowStr){
                    activeDj = dj;
                    break;
                }
            }
            if(activeDj == null){
               activeDj = latestSlot;
             }
            return activeDj;
        }

Open in new window

Avatar of VeyronSA
VeyronSA

ASKER

Ok, lol. Now i dont know how to integrate :D. A big beginner and a Newbie with this, can you show me please.
ASKER CERTIFIED SOLUTION
Avatar of petiex
petiex
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Genius!!!! Give this man a Medal!

Thanks