0

私のrandommessages.xmlには次のものがあります:

<?xml version="1.0" encoding="UTF-8" ?>
<messages> 
    <message name="First message is great" url="http://www.google.com/" /> 
    <message name="Second message is better. I hope so." url="http://www.yahoo.com/" /> 
    <message name="Third is the bomb. Dwonload now! Ok!" url="http://www.facebook.com/" /> 
</messages>

そして、ステージ上で表示するために使用しているこのコード:

onSelfEvent(load) 
{ 
    messageXml = new XML(); 
    messageXml.ignoreWhite = true; 
    messageXml.load("randommessages.xml"); 
    messageXml.onLoad = function(success) { 
    if (success) { 
        // some code here
        // ???? 
    } 
} 

} 
else { 
// failed loading
} 
}; 
dynamicmessageoutput._visible = false; 
}

実際には、表示されません。

ランダムなメッセージを 1 つ取得し、それをステージ上の dynamicmessageoutput という動的テキスト フィールドに表示する方法を教えてください。

4

1 に答える 1

1

ハンドラーで何をしようとしているのかよくわかりませんonSelfEventが、次のことは、あなたがやろうとしていることの良い出発点を提供するはずです:

var messageXml = new XML(); 
messageXml.ignoreWhite = true; 
messageXml.load("randommessages.xml"); 
messageXml.onLoad = function(success) { 
    if (success) { 
        // Get all the message nodes in an Array
        var messages = this.firstChild.childNodes;
        // Choose a random node from the Array
        var randomNode = messages[Math.round(Math.random() * (messages.length - 1))];
        // Grab the value of the 'name' attribute from the randomly selected node
        var randomMessage = randomNode.attributes['name'];

        trace(randomMessage);
    } else {
        trace("loading failed");
    }
}
于 2012-11-05T14:13:49.067 に答える