In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Strange XML parsing error

Get Adobe Flash player
by Quasimondo 02 Jun 2010

    Talk

    alinakipoglu at 02 Jun 2010 16:56
    var l:String = xml..parameter.(@id .contains("label")).@value.toString();
    SandroDucceschi at 02 Jun 2010 17:22
    writing a helper method apparently solves this problem aswell. See: http://wonderfl.net/c/c52a

    Tags

    Embed
/**
 * Copyright Quasimondo ( http://wonderfl.net/user/Quasimondo )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/7NY8
 */

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.accessibility.Accessibility;
    public class XMLTest extends Sprite {
        
        private var tf:TextField;
        
        private var xml:XML = <uielement type="Slider" label="Slider" ui="true" active="true" id="324">
							  <parameters>
							    <parameter id="decimals" value="0" label="Decimals" randomize="true" type="NUMBER" order="3" input="228"/>
							    <parameter id="value" value="0" label="Intensity" randomize="true" type="NUMBER" order="0" input="225" output="224"/>
							    <parameter id="max" value="100" label="Maximum Value" randomize="true" type="NUMBER" order="2" input="227"/>
							    <parameter id="label" value="Intensity" randomize="true" type="STRING" order="10"/>
							    <parameter id="order" value="0" randomize="true" type="NUMBER" order="11"/>
							    <parameter id="min" value="-100" label="Minimum Value" randomize="true" type="NUMBER" order="1" input="226"/>
							  </parameters>
							</uielement>
        
        public function XMLTest() 
        {
         	tf = new TextField();
		 	addChild( tf );
		 	tf.autoSize = "left";
         	
         	test1();
         	test2();
        }
        
        private function test1():void
        {
        		var l:String = xml..parameter.(@id=="label").@value;
					
			switch ( xml.@type.toString() )
			{
				case "Slider":
					tf.text = "Test 1: "+l + "\n";
				break;
				
				default:
				trace( xml.@type )
				break;
			}
			
		}	
        
        private function test2():void
        {
        		
			switch ( xml.@type.toString() )
			{
				case "Slider":
					
					// This still works:
					tf.appendText( "Test 2: "+xml..parameter.(@id=="label").@value +"\n");
					
					// This will cause an error
					// var l:String = xml..parameter.(@id=="label").@value;
				
					// This workaround found by @deafmetal fixes it:
					var l:String = "";
					l = xml..parameter.(@id=="label").@value;
				
				break;
				
				default:
				trace( xml.@type )
				break;
			}
			
		}		
		
			
			
        	
    }
}