Need help with adding a timer to my for each loop loading external XML data


i have actionscript have modified developphp.  script works fine (see code below).  problem have wanting add timer pause loop, way shows 1 listitem xml @ set time.  cool animation in , out great also, comes next.

 

right xml file has 3 list items (could more or less) , action script gets values each list item (see example below).  problem actionscript shows 3 drawing rectangle each listitem @ set distance apart each other, need happen show 1st listitem x seconds, move next , once lands on last listitem return first.

 

i new flash , know asp.net heart, getting confused in syntax , apis. help, examples, etc.. great!!

 

------------------------

xml file example

------------------------

<?xml version="1.0" encoding="utf-8"?>

<xml>

 

   <myxmllist>

      

       <listitem>

           <itemcolor>664204</itemcolor>

           <itemlabel>christmas party!</itemlabel>

           <itemtext>come join fun</itemtext>

       </listitem>

      

       <listitem>

           <itemcolor>664204</itemcolor>

           <itemlabel>announcement 2</itemlabel>

           <itemtext>stuff announcement 2</itemtext>      

       </listitem>

      

       <listitem>

           <itemcolor>664204</itemcolor>

           <itemlabel>announcement 3</itemlabel>

           <itemtext>there number of announcements in file</itemtext>      

       </listitem>             

  

   </myxmllist>

 

</xml>

 

 

---------------------------

actionscript - kinda long sorry that

--------------------------

import flash.text.textformat;

import flash.text.stylesheet;

import flash.text.textfield;

 

 

// set "y" location on stage first box live

var yplacement:int = 20;

// set "x" location on stage boxes line vertically

var xplacement:int = 30;

// set distance each box should apart here

var distance:int = 770; //wont needed after timer/pause figured out

 

// initialize xml, place xml file name, initialize urlrequest

// put urlrequest new urlloader, , add event listener on

// myloader listening when xml loading complete

var myxml:xml = new xml();

var xml_url:string = "myxmlfile.xml";

var myxmlurl:urlrequest = new urlrequest(xml_url);

var myloader:urlloader = new urlloader(myxmlurl);

myloader.addeventlistener("complete", xmlloaded);

 

// create xmlloaded function

function xmlloaded(event:event):void {

   

    // place xml data myxml object

    myxml = xml(myloader.data);

    // initialize , give var name new external xmldocument

    var xmldoc:xmldocument = new xmldocument();

    // ignore spacing around nodes

    xmldoc.ignorewhite = true;

    // define new name loaded xml data in myloader

    var menuxml:xml = xml(myloader.data);

    // parse xml data readable format

    xmldoc.parsexml(menuxml.toxmlstring());

   

    // store css styles in string variable

    var css1:string = ".bv{color:#fafafa; font-family:arial; font-size:32px; font-weight:bold; border:false;}";

    var css2:string = ".abv{color:#815303; font-family:arial; font-size:16px; font-weight:normal; border:false;}";

    // defines instance "stylesheet" object

    var styles1:stylesheet = new stylesheet();

    var styles2:stylesheet = new stylesheet();

    // applies "parsecss" method variable css styles

    styles1.parsecss(css1);

    styles2.parsecss(css2);

   

 

         // run "for each" loop iterate through of menu items listed in external xml file

        each (var listitem:xml in myxml..listitem) {

                 // access value of "itemcolor" node in our external xml file

                 var listcolor:string = listitem.itemcolor.tostring();

                 // access value of "itemlabel" node in our external xml file

                 var listlabel:string = listitem.itemlabel.tostring();

                 // access value of "itemphone" node in our external xml file

                 var listtext:string = listitem.itemtext.tostring();

                

                 // pertains style of box holds each person

                 var rect:shape = new shape;

                 var color:number = number("0x"+listcolor);

                 rect.graphics.beginfill(color);

                 rect.graphics.linestyle(0, 0x000000);

                  // draw box

                 rect.graphics.drawroundrect(0, 0, 745, 175, 10);

                 rect.alpha = 0.3;

                

                 // pertains text fields give our boxes labels

                 var mytext1:textfield = new textfield();

                 mytext1.stylesheet = styles1;

                 mytext1.text = '<span class="bv">'+listlabel+'</span>'; // uses "stylesheet" property bv attach css styles "txt" instance

                 mytext1.autosize = textfieldautosize.left;

                 mytext1.x = 2;

                 mytext1.y = 2;

                

                  var mytext2:textfield = new textfield();

                  mytext2.stylesheet = styles2;

                  mytext2.text = '<span class="abv">'+listtext+'</span>'; // uses "stylesheet" property bv attach css styles "txt" instance

                  mytext2.multiline = true;

                  mytext2.wordwrap = true;

                  mytext2.width = 740;

                  mytext2.height = 170;

                  mytext2.x = 10;

                  mytext2.y = 25;

                 

                            

                               // create movieclip holder each box graphic , text labels organize container

                             var clip_mc = new movieclip();

                             //add rectangle graphic

                             clip_mc.addchild(rect);

                             // add text fields

                             clip_mc.addchild(mytext1);

                             clip_mc.addchild(mytext2);                            

                             // put new movieclip on stage now

                             addchild(clip_mc);        

                            

                             // apply in offset y position stage

                             clip_mc.y = yplacement;

                             // x position placed on stage

                             clip_mc.x = xplacement;      

                             // offset each 1 in loop make sure don't put right on top of each other

                             xplacement = xplacement + distance; //this line removed once pause/timer function figured out

                            

                                             

        }

       

}

don't use for-loop then.  create function that's called timer instance add next listitem.  done, update next listitem.

 

 

import flash.text.textformat;

import flash.text.stylesheet;

import flash.text.textfield;

 

 

// set "y" location on stage first box live

var yplacement:int = 20;

// set "x" location on stage boxes line vertically

var xplacement:int = 30;

// set distance each box should apart here

var distance:int = 770; //wont needed after timer/pause figured out

 

// initialize xml, place xml file name, initialize urlrequest

// put urlrequest new urlloader, , add event listener on

// myloader listening when xml loading complete

var myxml:xml = new xml();

var xml_url:string = "myxmlfile.xml";

var myxmlurl:urlrequest = new urlrequest(xml_url);

var myloader:urlloader = new urlloader(myxmlurl);

myloader.addeventlistener("complete", xmlloaded);

 

var clip_mc:movieclip;

var nextitemfrequency:int = 3000;  // 3000 ms

var t:timer=new timer(nextitemfrequency,1);

t.addeventlistener(timerevent.timer,nextlistitemf);

 

var nextlistitemindex:int=0;

 

    // store css styles in string variable

    var css1:string = ".bv{color:#fafafa; font-family:arial; font-size:32px; font-weight:bold; border:false;}";

    var css2:string = ".abv{color:#815303; font-family:arial; font-size:16px; font-weight:normal; border:false;}";

    // defines instance "stylesheet" object

    var styles1:stylesheet = new stylesheet();

    var styles2:stylesheet = new stylesheet();

    // applies "parsecss" method variable css styles

    styles1.parsecss(css1);

    styles2.parsecss(css2);

 

// create xmlloaded function

function xmlloaded(event:event):void {

 

    // place xml data myxml object

    myxml = xml(myloader.data);

nextlistitemf();

}

 

function nextlistitemf():void{

var listitem = myxml.listitem[nextlistitemindex];

                 // access value of "itemcolor" node in our external xml file

                 var listcolor:string = listitem.itemcolor.tostring();

                 // access value of "itemlabel" node in our external xml file

                 var listlabel:string = listitem.itemlabel.tostring();

                 // access value of "itemphone" node in our external xml file

                 var listtext:string = listitem.itemtext.tostring();

                 // pertains style of box holds each person

                 var rect:shape = new shape;

                 var color:number = number("0x"+listcolor);

                 rect.graphics.beginfill(color);

                 rect.graphics.linestyle(0, 0x000000);

                  // draw box

                 rect.graphics.drawroundrect(0, 0, 745, 175, 10);

                 rect.alpha = 0.3;

                 // pertains text fields give our boxes labels

                 var mytext1:textfield = new textfield();

                 mytext1.stylesheet = styles1;

                 mytext1.text = '<span class="bv">'+listlabel+'</span>'; // uses "stylesheet" property bv attach css styles "txt" instance

                 mytext1.autosize = textfieldautosize.left;

                 mytext1.x = 2;

                 mytext1.y = 2;

                  var mytext2:textfield = new textfield();

                  mytext2.stylesheet = styles2;

                  mytext2.text = '<span class="abv">'+listtext+'</span>'; // uses "stylesheet" property bv attach css styles "txt" instance

                  mytext2.multiline = true;

                  mytext2.wordwrap = true;

                  mytext2.width = 740;

                  mytext2.height = 170;

                  mytext2.x = 10;

                  mytext2.y = 25;                 

                               // create movieclip holder each box graphic , text labels organize container

if(clip_mc){

removechild(clip_mc);

}

                             clip_mc = new movieclip();

                             //add rectangle graphic

                             clip_mc.addchild(rect);

                             // add text fields

                             clip_mc.addchild(mytext1);

                             clip_mc.addchild(mytext2);                            

                             // put new movieclip on stage now

                             addchild(clip_mc);        

 

                             // apply in offset y position stage

                             clip_mc.y = yplacement;

                             // x position placed on stage

                             clip_mc.x = xplacement;      

                             // offset each 1 in loop make sure don't put right on top of each other

                             xplacement = xplacement + distance; //this line removed once pause/timer function figured out

  nextlistitemindex=(nextlistitemindex+1)%myxml.listitem.length();     

t.reset();

t.start();                              

        }



More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

Joomla 3.3 Installation Error message - Joomla! Forum - community, help and support

Multilanguage infinite redirect loop error. - Joomla! Forum - community, help and support

trim media limit reached