2015-04-28 89 views
1

下面的代码从XML列表中带回9个摄影子实例。然后我想要做的是,当用户点击其中一个返回值时,它将删除所有摄影值并加载具有该孩子图像的用户。即当单击运动时,将会返回安全提示,并返回XML文件中的任何其他名称。操作xml数据actionscript

 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); 
      } 
     } 

XML文件

<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> 
+0

你的代码看起来还好。它不是做你想做的事吗?有几种方法可以改进它,但它会做同样的事情。不太清楚你的问题实际上是什么。 – Aaron

+0

@ user3658394感谢您的澄清。每个问题只能提出一个问题。不要将所有内容添加到评论中,请编辑您的问题。 – null

+0

嗨亚伦。也许我没有把我的问题弄清楚。为了更加清晰,我编辑了上面的文字。我会接受你的建议:) – caribou

回答

1

这不是有效的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> 

轮廓标签永远不会关闭。

关于你的代码中的本地变量应该使用括号:

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); 

    } 
} 
+0

感谢您的建议。我的XML是正确的,我发布时错误地删除了结束标签。不是常规的AS用户,我确实有一些不好的做法,但我会听取您的建议并尝试在未来实施它们。如果您提供更多建议,我已在上述帖子中澄清了我的问题。 – caribou