1

The code below brings back 9 instances of the photography child from the XML list. What I then want to do is when the user clicks on one of the returned values it then removes all the photography values and loads the users that have an image with that child. ie when sport is clicked ann lee will then be returned plus any other names in the XML file.

        var list:XMLList = xmlinfo.profile.photography;

        var totalimage:Number = list.length();
        trace("length" + totalimage);

        for (var i:int =0; i<totalimage; i++){
            trace(xmlinfo.profile.photography[i]);


    //bkg.addEventListener(MouseEvent.CLICK,gotodata);
        background = new bkg();


        background.y = i*40;
        background.x = 20;
        addChild(background);

        textField = new TextField();
        textField.text = list[i];    
        background.addChild(textField);
            }
        }

the XML FILE

<root>
  <profile>   
      <name>ann lee</name>
      <photography>sport</photography>
      <photography>landscape</photography>
      <photography>still life</photography>           
      <image>img1.jpg</image>
  </profile> <profile>        
      <name>john</name>
      <photography>wildlife</photography>
      <photography>landscape</photography>
      <image>img2.jpg</image> </profile>  
</root>
3
  • Your code looks okay. Does it not do what you want? There are a few ways I could suggest to improve it but it would do the same thing. Not quite sure what your question actually is. Commented Apr 28, 2015 at 14:41
  • @user3658394 thank you for your clarification. Please only ask one question per question. Instead of adding all of that into a comment, edit your question. Commented Apr 29, 2015 at 14:06
  • Hi Aaron. Maybe I didn't make my question very clear. I edited the text above for more clarity. I will accept any advice you have to give :) Commented Apr 29, 2015 at 15:52

1 Answer 1

1

That is not valid xml:

<root>
<profile>   
    <name>ann lee</name>
    <photography>sport</photography>
    <photography>landscape</photography>
    <photography>still life</photography>           
    <image>img1.jpg</image>
<profile>   
    <name>john</name>
    <photography>wildlife</photography>
    <photography>landscape</photography>
    <image>img2.jpg</image>
</root>

The profile tags are never closed.

Regarding your code local variables should be used instead of brackets:

var background:bkg;  //you should use names with better meaning and use capital letters for class names (compare to the next line, example: var background:Background;
var textField:TextField;  

for (var i:int =0; i<totalimage; i++){
    trace(xmlinfo.profile.photography[i]);


    background.addEventListener(MouseEvent.CLICK,gotodata);

    background = new bkg();
    background.y = i*40;
    background.x = 20;
    addChild(background);

    textField = new TextField();
    textField.text = list[i];    
    background.addChild(textField);

    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the advice. My XML was correct, I deleted the closing tags by mistake while posting. Not being a regular AS user I do have some bad practices but I will take your advice and try to implement them in the future. I have clarified my question in the post above should you offer some more advice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.