# Trouble creating Dynamic XML Active State Buttons

**URL:** <https://forum.kirupa.com/t/trouble-creating-dynamic-xml-active-state-buttons/296009>\
**Category:** flash\
**Created:** [September 8, 2009, 4:58pm UTC](https://forum.kirupa.com/t/trouble-creating-dynamic-xml-active-state-buttons/296009 "2009-09-08T16:58:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dschmidt20](https://avatars.discourse-cdn.com/v4/letter/d/b38774/32.png) [@dschmidt20](https://forum.kirupa.com/u/dschmidt20)\
**Post date:** [September 8, 2009, 4:58pm UTC](https://forum.kirupa.com/t/trouble-creating-dynamic-xml-active-state-buttons/296009/1 "2009-09-08T16:58:53Z")

</div>

Hey everyone. I’m looking for an AS3/XML parsing pro to help me with an issue I’m having. The following xml file loads 7 icons (“url”) into an array. What I want to do is create an activestate using child (“activestate”) that replaces the “url” icon when clicked. I have no idea what the best way to do this would be. I’ve tried everything. The reason for this application is if i decide to change up the content down the line I won’t have to recode anything. Just update the icons.

xml

\<?xml version=“1.0” encoding=“utf-8”?\>  
\<images\>  
\<image\>  
\<url\>pics/construct.jpg\</url\>  
\<activestate\>pics/active/construct.jpg\</activestate\>  
\<big\_url\>\<![CDATA[swf/construct.swf]]\>\</big\_url\>  
\</image\>  
\<image\>  
\<url\>pics/energy.jpg\</url\>  
\<activestate\>pics/active/energy.jpg\</activestate\>  
\<big\_url\>\<![CDATA[swf/energy.swf]]\>\</big\_url\>  
\</image\>  
\<image\>  
\<url\>pics/water.jpg\</url\>  
\<activestate\>pics/active/water.jpg\</activestate\>  
\<big\_url\>\<![CDATA[swf/water.swf]]\>\</big\_url\>  
\</image\>  
\<image\>  
\<url\>pics/sustain.jpg\</url\>  
\<activestate\>pics/active/sustain.jpg\</activestate\>  
\<big\_url\>\<![CDATA[swf/sustain.swf]]\>\</big\_url\>  
\</image\>  
\<image\>  
\<url\>pics/recycle.jpg\</url\>  
\<activestate\>pics/active/recycle.jpg\</activestate\>  
\<big\_url\>\<![CDATA[swf/recycle.swf]]\>\</big\_url\>  
\</image\>  
\<image\>  
\<url\>pics/air.jpg\</url\>  
\<activestate\>pics/active/air.jpg\</activestate\>  
\<big\_url\>\<![CDATA[swf/air.swf]]\>\</big\_url\>  
\</image\>  
\<image\>  
\<url\>pics/clean.jpg\</url\>  
\<activestate\>pics/active/clean.jpg\</activestate\>  
\<big\_url\>\<![CDATA[swf/clean.swf]]\>\</big\_url\>  
\</image\>  
\</images\>

AS3

import fl.containers.UILoader;  
import caurina.transitions.\*;

//---------loading the external xml file-------  
var urlRequest:URLRequest = new URLRequest(“xml/pics.xml”);  
var urlLoader:URLLoader = new URLLoader();  
var myXML:XML = new XML();  
var xmlList:XMLList;  
myXML.ignoreWhitespace = true;  
urlLoader.addEventListener(Event.COMPLETE,fileLoaded);  
urlLoader.load(urlRequest);  
//--------holds the paths to the thumbnails-------  
var arrayURL:Array = new Array();  
//--------holds the paths to the big photos-------  
var arrayName:Array = new Array();  
//--------holds the thumbnail objects-------  
var holderArray:Array = new Array();  
//--------represents the number of collumns-------  
var nrColumns:uint = 7;  
//-------represents the container of our gallery  
var sprite:Sprite = new Sprite();  
addChild(sprite);  
var thumb:Thumbnail;  
//-------- the thumbnails container-------  
var thumbsHolder:Sprite = new Sprite();  
thumbsHolder.graphics.beginFill(0xffffff,1);  
thumbsHolder.graphics.drawRect(-80,-320,960,494);  
thumbsHolder.graphics.endFill();  
thumbsHolder.x = 100;  
thumbsHolder.y = 425;  
sprite.addChild(thumbsHolder);  
//-------- the photoLoader container-------  
var loaderHolder:Sprite = new Sprite();  
loaderHolder.x = 1000;  
loaderHolder.y = 10;  
sprite.addChild(loaderHolder);  
//-------- loads the swf-------  
var photoLoader:UILoader = new UILoader();  
photoLoader.width = 800;  
photoLoader.height = 300;  
photoLoader.buttonMode = true;  
photoLoader.addEventListener(MouseEvent.CLICK,onClickBack);  
loaderHolder.addChild(photoLoader);  
/\* we loop through the xml file  
populate the arrayURL, arrayName and position the thumbnalis\*/  
function fileLoaded(event:Event):void {  
myXML = XML(event.target.data);  
xmlList = myXML.children();  
for (var i:int=0; i\<xmlList.length(); i++) {  
var picURL:String = xmlList\*.url;  
var picName:String = xmlList\*.big\_url;  
arrayURL.push(picURL);  
arrayName.push(picName);  
holderArray\* = new Thumbnail(arrayURL\*,i,arrayName\*);  
holderArray\*.addEventListener(MouseEvent.CLICK,onClick);  
holderArray\*.name = arrayName\*;  
holderArray\*.buttonMode = true;  
if (i\<nrColumns) {  
holderArray\*.y = 65;  
holderArray\*.x = i_110+65;  
} else {  
holderArray_.y = holderArray[i-nrColumns].y+110;  
holderArray\*.x = holderArray[i-nrColumns].x;  
}  
thumbsHolder.addChild(holderArray\*);  
}  
}  
//----handles the Click event added to the thumbnails–  
function onClick(event:MouseEvent):void {  
photoLoader.source = event.currentTarget.name;  
Tweener.addTween(loaderHolder, {x:10, time:1, transition:“easeInElastic”});  
Tweener.addTween(loaderHolder, {alpha:1, time:1, transition:“linear”});  
}  
//----handles the Click event added to the photoLoader----  
function onClickBack(event:MouseEvent):void {  
Tweener.addTween(loaderHolder, {x:1000, time:1, transition:“easeInElastic”});  
Tweener.addTween(loaderHolder, {alpha:0, time:2, transition:“linear”});  
}

Thank you for your help in advance.
