# XML swf player: Auto Start and Loop

**URL:** <https://forum.kirupa.com/t/xml-swf-player-auto-start-and-loop/265591>\
**Category:** Uncategorized\
**Created:** [July 10, 2008, 3:19pm UTC](https://forum.kirupa.com/t/xml-swf-player-auto-start-and-loop/265591 "2008-07-10T15:19:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbarrett78](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@jbarrett78](https://forum.kirupa.com/u/jbarrett78)\
**Post date:** [July 10, 2008, 3:19pm UTC](https://forum.kirupa.com/t/xml-swf-player-auto-start-and-loop/265591/1 "2008-07-10T15:19:57Z")

</div>

Hello,

First of all, the code:

```auto

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoaded);

lb.addEventListener(Event.CHANGE, itemChange);

function itemChange(e:Event):void
{
    ta.source = lb.selectedItem.data;
}
var xml:XML;
function onLoaded(e:Event):void
{
    xml= new XML(e.target.data);
    var il:XMLList = xml.dave.movie;
    for(var i:uint=0; i<il.length(); i++)
    {
        lb.addItem({data:il.href.text()*,
                     label:il.gary.text()*});
    }
}

loader.load(new URLRequest("xml.xml"));

```

As of right now, i can manually select and play swfs no problem. I followed a great tutorial on gotoandlearn, which got me up to speed on how CS3 handles XML. My question is two-fold. 1) How can I get the first node to start playing right away, and then how can I get them to loop? thanks a lot guys!

---

<div class="post-metadata">

**Author:** ![koolkrasher](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@koolkrasher](https://forum.kirupa.com/u/koolkrasher)\
**Post date:** [July 10, 2008, 4:46pm UTC](https://forum.kirupa.com/t/xml-swf-player-auto-start-and-loop/265591/2 "2008-07-10T16:46:16Z")

</div>

Ha ha that looks very fimilar.

you would do it like this.  
added code is in bold

```auto

/*sets the change to go off every 5 seconds timer is set in ms (1000 = 1 second) */

**var swichTimer:Timer = new Timer(5000);
swicthTimer.addEventListener (TimerEvent.TIMER, autoChange);

function autoChange (event:TimerEvent):void
{
/* this is set up to handle 11 entrys in you list just change the number accordingly*/
    if (lb.selectedIndex!=10)
    {
        lb.selectedIndex++;
        
    } else if (lb.selectedIndex>=10)
    {
        lb.selectedIndex = 0;
        
    }
}**

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoaded);

lb.addEventListener(Event.CHANGE, itemChange);

function itemChange(e:Event):void
{
    ta.source = lb.selectedItem.data;
}
var xml:XML;
function onLoaded(e:Event):void
{
    xml= new XML(e.target.data);
    var il:XMLList = xml.dave.movie;
    for(var i:uint=0; i<il.length(); i++)
    {
        lb.addItem({data:il.href.text()*,
                     label:il.gary.text()*});
    }
**       
/* sets selected index to 0 and selected item to 0 */
          lb.selectedItem = 0;
          lb.selectedIndex = 0;
**
**switchTimer.start();**
}

loader.load(new URLRequest("xml.xml"));

```

---

<div class="post-metadata">

**Author:** ![jbarrett78](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@jbarrett78](https://forum.kirupa.com/u/jbarrett78)\
**Post date:** [July 10, 2008, 6:50pm UTC](https://forum.kirupa.com/t/xml-swf-player-auto-start-and-loop/265591/3 "2008-07-10T18:50:40Z")

</div>

Thanks! I had to tweak it a little for some custom stuff were doing but you solved a big chunk. Thanks again.

---

<div class="post-metadata">

**Author:** ![koolkrasher](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@koolkrasher](https://forum.kirupa.com/u/koolkrasher)\
**Post date:** [July 10, 2008, 7:16pm UTC](https://forum.kirupa.com/t/xml-swf-player-auto-start-and-loop/265591/4 "2008-07-10T19:16:51Z")

</div>

glad to help

---

<div class="post-metadata">

**Author:** ![jbarrett78](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@jbarrett78](https://forum.kirupa.com/u/jbarrett78)\
**Post date:** [July 10, 2008, 7:54pm UTC](https://forum.kirupa.com/t/xml-swf-player-auto-start-and-loop/265591/5 "2008-07-10T19:54:01Z")

</div>

one last thing, that I can’t figure out.

```auto

var itemCount = 0;
box.text= itemCount;
var switchTimer:Timer = new Timer(5000);
switchTimer.addEventListener (TimerEvent.TIMER, autoChange);

function autoChange (event:TimerEvent):void
{
    if (lb.selectedIndex!=itemCount)
    {
        lb.selectedIndex++;

    } else if (lb.selectedIndex>=itemCount)
    {
        lb.selectedIndex = 0;
        
    }
        ta.source = lb.selectedItem.data;
}
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoaded);

lb.addEventListener(Event.CHANGE, itemChange);
//lb.addEventListener(Event.RENDER, itemChange);

function itemChange(e:Event):void
{
    ta.source = lb.selectedItem.data;
}
var xml:XML;
function onLoaded(e:Event):void
{
    xml= new XML(e.target.data);
    var il:XMLList = xml.dave.movie;
    itemCount = il.length()-1;
    for(var i:uint=0; i<il.length(); i++)
    {
        lb.addItem({data:il.href.text()*,
                     label:il.gary.text()*});
    }
       
/* sets selected index to 0 and selected item to 0 */
          lb.selectedItem = 0;
          lb.selectedIndex = 0;

 switchTimer.start();
}

loader.load(new URLRequest("xml.xml"));

```

This first time it hits the 1st node (this this case, “swf”) it doesn’t play, but when it refreshes back to the beginning, it plays fine. Any thoughts?

---

<div class="post-metadata">

**Author:** ![koolkrasher](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@koolkrasher](https://forum.kirupa.com/u/koolkrasher)\
**Post date:** [July 10, 2008, 8:40pm UTC](https://forum.kirupa.com/t/xml-swf-player-auto-start-and-loop/265591/6 "2008-07-10T20:40:43Z")

</div>

not sure why its not starting on the first loop. It works fine for me

---

<div class="post-metadata">

**Author:** ![jbarrett78](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@jbarrett78](https://forum.kirupa.com/u/jbarrett78)\
**Post date:** [July 10, 2008, 8:50pm UTC](https://forum.kirupa.com/t/xml-swf-player-auto-start-and-loop/265591/7 "2008-07-10T20:50:10Z")

</div>

weird. i emailed it to a co worker that has flash and he’s having the same problem. one of our developers (doesn’t really know flash) told me that it might have something to do with the itemChange not updating. I can’t for the life of me figure it out 😛

---

<div class="post-metadata">

**Author:** ![koolkrasher](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@koolkrasher](https://forum.kirupa.com/u/koolkrasher)\
**Post date:** [July 10, 2008, 10:13pm UTC](https://forum.kirupa.com/t/xml-swf-player-auto-start-and-loop/265591/8 "2008-07-10T22:13:02Z")

</div>

can you send me a moc file? maby i can figure it out if i see the whole thing
