mercredi 24 juin 2015

converting XML data into an array of objects AS3

I'm using Flash AS4 and Ive created and array that holds xml data which works fine with the following loop

for(var i:int = 0; i < uNavXML.length(); i++){
    navArray.push(uNavXML..navRef.text()[i]);

The XML data is actually the names of movie clips that I have on stage:

    xmlLIST :<uNav>
  <unavNavID>1</unavNavID>
  <navRef>navBtns.nav01</navRef>
</uNav>
<uNav>
  <unavNavID>2</unavNavID>
  <navRef>navBtns.nav02</navRef>
</uNav>
<uNav>
  <unavNavID>3</unavNavID>
  <navRef>navBtns.nav03</navRef>
</uNav>
<uNav>
  <unavNavID>4</unavNavID>
  <navRef>navBtns.nav04</navRef>
</uNav>
<uNav>
  <unavNavID>5</unavNavID>
  <navRef>navBtns.nav05</navRef>
</uNav>
<uNav>
  <unavNavID>7</unavNavID>
  <navRef>navBtns.nav07</navRef>
</uNav>
<uNav>
  <unavNavID>8</unavNavID>
  <navRef>navBtns.nav08</navRef>
</uNav>
<uNav>
  <unavNavID>10</unavNavID>
  <navRef>navBtns.nav10</navRef>
</uNav>
<uNav>
  <unavNavID>12</unavNavID>
  <navRef>navBtns.nav12</navRef>
</uNav>
<uNav>
  <unavNavID>13</unavNavID>
  <navRef>navBtns.nav13</navRef>
</uNav>
<uNav>
  <unavNavID>14</unavNavID>
  <navRef>navBtns.nav14</navRef>
</uNav>
<uNav>
  <unavNavID>15</unavNavID>
  <navRef>navBtns.nav15</navRef>
</uNav>

So, what I want to do is to take these xml values, make them objects in the for loop so that I can then assign eventlisteners to them like this

navObj[i].addEventListener(MouseEvent.MOUSE_OVER, mOvNav); navObj[i].addEventListener(MouseEvent.MOUSE_OUT,mOuNav); navObj[i].addEventListener(MouseEvent.CLICK,goPage);

Is there a way to do this in Flash actionScript? I'm not terribly experienced with AS3 and I've never had to convert an array from String to Object before so I'm struggling. If anyone can off help it would be warmly received...

Answer found via this and on previous SO quesiotn Converting String values to MovieClip in AS 3.0

For my issue here was the answer to remove the "navBtns." prfix and just supply the navButton instance name via navShort

for each (var nav:String in navShrt) {
    var navInst:MovieClip = navBtns[nav] as MovieClip;

Then I was able to reference via navInst.addEventListener.... etc

Aucun commentaire:

Enregistrer un commentaire