A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Annoying problem with XMLList assignment

  1. #1
    Member
    Join Date
    Jan 2009
    Posts
    30

    Annoying problem with XMLList assignment

    Hi guys. I'm creating this XMLList everytime someone clicks a button on my page. As you it's assigned to this static "xml.buildings.projekt" - but I'd like to have it as a variable instead (preferably a string) but I don't the syntax for this.

    This works, but it's static:

    var projektList:XMLList = xml.buildings.projekt;

    I'd like to be like this, dynamic that is:

    var projektList:XMLList = xml.STRING.projekt;

    But that doesn't work, I get this error when I try that:

    1067: Implicit coercion of a value of type String to an unrelated type XMLList.

    Anyone know how to solve this? Is it simply a matter of me using the wrong damn syntax?

    I'd be very thankful if someone could shed me some light on this!

  2. #2
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    you can use array access:
    PHP Code:
    var projektlist:XMLList xml["buildings"].projekt
    e.g.,
    PHP Code:
    var xml:XML = <root>
        <
    buildings>
            <
    item>building 1</item>
            <
    item>building 2</item>
            <
    item>building 3</item>
        </
    buildings>
        <
    somethingelse>
            <
    item>somethingelse 1</item>
            <
    item>somethingelse 2</item>
            <
    item>somethingelse 3</item>
        </
    somethingelse>
    </
    root>

    trace(xml["buildings"].item); 

  3. #3
    Member
    Join Date
    Jan 2009
    Posts
    30
    Quote Originally Posted by moagrius
    you can use array access:
    PHP Code:
    var projektlist:XMLList xml["buildings"].projekt
    e.g.,
    PHP Code:
    var xml:XML = <root>
        <
    buildings>
            <
    item>building 1</item>
            <
    item>building 2</item>
            <
    item>building 3</item>
        </
    buildings>
        <
    somethingelse>
            <
    item>somethingelse 1</item>
            <
    item>somethingelse 2</item>
            <
    item>somethingelse 3</item>
        </
    somethingelse>
    </
    root>

    trace(xml["buildings"].item); 
    Thanks moagrius! That solved it perfectly!

  4. #4
    ___________________
    Join Date
    May 2004
    Posts
    3,174

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