Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 08-29-2011, 07:31 AM   #1
aca98atw
Senior Member
 
Join Date: Nov 2009
Posts: 123
Default searching through all descendants of XML and replacing instances of text

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;             }         }

Last edited by aca98atw; 08-29-2011 at 07:41 AM.
aca98atw is offline   Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:47 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.