Hi all,
can anyone suggest a cleaner way of searching through all of the descendants of an XML object and replacing all % values with actual values. I specify x, y, height and width positions in terms of percentages, and so must convert these to actual positions - it seems madness to first search and replace x values, then y values, then...
The below seems like quite a waste of coding.
Thanks,
Andy.
ActionScript Code:
var menuSpec:XML=XML(
<header>
<title>oldExpts</title>
<x>5%</x>
<y>50%</y>
<subheader>
<title>subheader</title>
<x>5%</x>
<y>50%</y>
<width>80%<width>
</subheader>
</header>);
private function sortOutPercentages(){
//if(menuSpec..*.toString().indexOf("%")!=-1));
//trace(menuSpec.descendants().(x==50));
var castNodes:XMLList = menuSpec..*.(y.toString().indexOf("%") != "-1");
for each (var castNode:XML in castNodes){
tempInt=int(castNode.y.toString().slice(0,-1))/100*the_Sta.stageHeight;
castNode.y=tempInt;
}
castNodes = menuSpec..*.(x.toString().indexOf("%") != "-1");
for each (castNode in castNodes){
tempInt=int(castNode.x.toString().slice(0,-1))/100*the_Sta.stageWidth;
castNode.x=tempInt;
}
castNodes = menuSpec..*.(width.toString().indexOf("%") != "-1");
for each (castNode in castNodes){
tempInt=int(castNode.width[0].slice(0,-1))/100*the_Sta.stageWidth;
castNode.width=tempInt;
}
castNodes = menuSpec..*.(height.toString().indexOf("%") != "-1");
for each (castNode in castNodes){
tempInt=int(castNode.height[0].slice(0,-1))/100*the_Sta.stageHeight;
castNode.height=tempInt;
}
}