A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Using as XML

  1. #1

    Using as XML

    I want to know why I can't use this code
    PHP Code:
    var xml:XML = new XML();

    var 
    loader:URLLoader = new URLLoader();

    function 
    xmlloaded(e:Event):void {
        
        
    xml=e.target.data as XML;
            
            
    trace(xml.toString());

    }

    loader.load(new URLRequest('photogallery.xml'));

    loader.addEventListener(Event.COMPLETE,xmlloaded); 
    I know the problem is
    Code:
    xml=e.target.data as XML;
    but I want to know why I can't use the as XML instead of XML(e.target.data)?

    thank you

    www.onenterflash.com | Learn Free

  2. #2
    ReMember gobbles's Avatar
    Join Date
    Nov 2002
    Location
    Denmark
    Posts
    983
    Try

    PHP Code:
    xml = new XML(loader.data
    The way you are doing it, I think only works for DataEvents.
    http://www.rickigregersen.com ...finally a blog!

    Your damned if you do...but your particually damned if you don´t

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Using the as operator casts one class to another. It only works if that object actually IS an instance of the cast-to class. Strings are not XML.

    Using XML(data) or new XML(data) actually calls functions which parse the string into XML. The syntax is very misleading since you would think that XML(data) is casting data to XML, but in fact there is a top-level XML function which converts an object to XML.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center