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

XML appendChild

Why doesn't appendChild always go to the end?
Get Adobe Flash player
by wh0 01 Mar 2011

    Talk

    makc3d at 01 Mar 2011 16:27
    maybe XML.ignoreWhitespace = true; would help

    Tags

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

package {
    import com.actionscriptbible.Example;
    public class FlashTest extends Example {
        
        public function FlashTest() {
            trace2 = trace;
            new C().foo();
        }
        
    }
}

internal var trace2:Function;
internal var NOTHING:XML = XML('');

internal class A {
    
    public function foo():XML {
        var x:XML = <foo />;
        x.appendChild(
            bar('one') +
            NOTHING
        );
        return x;
    }
    
    protected function bar(id:String):XML {
        return (<bar id={id} />);
    }
    
}

internal class B extends A {
    
    override public function foo():XML {
        var x:XML = super.foo();
        x.appendChild(
            bar('two') +
            NOTHING
        );
        return x;
    }
    
}

internal class C extends B {
    
    override public function foo():XML {
        var x:XML = super.foo();
        trace2('C.foo starts with:\n' + x + '\n');
        x.appendChild(
            bar('three')
        );
        trace2('C.foo returns:\n' + x + '\n');
        return x;
    }
    
}