Copy link to clipboard
Copied
I would love to make a wheel of fortune puzzleboard.
How can I make one? Should I use a text file or XML?
Copy link to clipboard
Copied
xml is easier to parse.
Copy link to clipboard
Copied
Can you show me how to?
Copy link to clipboard
Copied
How can I parse the XML data in Animate CC?
Copy link to clipboard
Copied
var r = new XMLHttpRequest();
r.open("GET", "your xml file.xml", true);
r.addEventListener("load", rF);
r.send();
function rF(e) {
parser = new DOMParser();
var xml = parser.parseFromString(e.target.response, "text/xml");
// the exact parsing depends on the structure of the loaded xml file.
alert(xml.getElementsByTagName("a tag name")[0].childNodes[0].nodeValue);
}
Copy link to clipboard
Copied
Thanks. Will this work with the Jeopardy game also?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
what errors and what code are you using?
Copy link to clipboard
Copied
I used the code above. Next I tried to use the URLLoader code, but when I tried it, nothing showed up.
Am I doing something wrong?
This is the code I'm using now...
var myXML:XML = new XML();
var myXMLURL:URLRequest = new URLRequest("puzzle1.xml");
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(e:Event):void{
myXML = XML(myLoader.data);
var myAnswers:Sprite = new Sprite;
myAnswers.name = "answers";
answers_mc.addChild(myAnswers);
var answers:XMLList = myXML.children();
var numAnswers:int = answers.length();
var i:int = 0;
for(i=0; i<numAnswers; i++){
var myAns:Answer = new Answer();
myAns.answer_txt = answers.attributes("name");
}
}
Copy link to clipboard
Copied
are you creating an as3 project or html5/canvas?
Copy link to clipboard
Copied
I am creating an as3 project
Copy link to clipboard
Copied
you probably want:
var myXML:XML = new XML();
var myXMLURL:URLRequest = new URLRequest("puzzle1.xml");
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(e:Event):void{
myXML = XML(myLoader.data);
var myAnswers:Sprite = new Sprite;
myAnswers.name = "answers";
answers_mc.addChild(myAnswers);
var answers:XMLList = myXML.children()[0].children();
var numAnswers:int = answers.length();
var i:int = 0;
for(i=0; i<numAnswers; i++){
var myAns:Answer = new Answer();
myAns.answer_txt = answers[i]);
}
}
Copy link to clipboard
Copied
Tried it, but it says "Type Coercion failed: cannot convert XML@40eafff23a1 to flash.text.TextField."
What should I do?
Copy link to clipboard
Copied
use:
for(i=0; i<numAnswers; i++){
var myAns:Answer = new Answer();
myAns.answer_txt.text += answers[i].toString();
}
}
Copy link to clipboard
Copied
Now it's saying "A term is undefined and has no properties."
I think it has something to do with the XML document. What should I do now?
var xmlRequest:URLRequest = new URLRequest("puzzle.xml");
var myLoader:URLLoader = new URLLoader(xmlRequest);
var puzzle:XML;
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(e:Event):void{
puzzle = XML(myLoader.data);
var myAnswers:Sprite = new Sprite;
myAnswers.name = "letters";
answers_mc.addChild(myAnswers);
var letters:XMLList = puzzle.children();
var numAnswers:int = letters.length();
var i:int = 0;
for(i=0; i<numAnswers; i++){
var myAns:Answer = new Answer();
myAns.answer_txt.text += letters[i].toString();
}
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
click file>publish settings>tick "enable debugging">retest.
the error message will reappear with the problematic line number. if that doesn't make the solution obvious to you, indicate the problematic line of code.
Copy link to clipboard
Copied
Well, I finally figured out a formula. How can I do the addChild effect?
var xmlRequest:URLRequest = new URLRequest("puzzle.xml");
var myLoader:URLLoader = new URLLoader(xmlRequest);
var puzzle:XML;
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(e:Event):void{
puzzle = XML(e.target.data);
letter_txt.text = puzzle.item.answers.answer[0];
trace("Data loaded.");
}
Copy link to clipboard
Copied
by the "addChild effect", do you mean you want to display all your answers in a separate textfield?:
Copy link to clipboard
Copied
Yes I do.
Copy link to clipboard
Copied
do you have those textfields on stage or are you going to create them dynamically (by having a textfield in a movieclip and that movieclip has a linkage id)?
Copy link to clipboard
Copied
create them dynamically
Copy link to clipboard
Copied
textfield in a movieclip and the movieclip has a linkage id
can you show me how to do textfields on stage as well?
Copy link to clipboard
Copied
create a new movieclip with a textfield tf. assign class name TF_MC.
var myXML: XML = new XML();
var myXMLURL: URLRequest = new URLRequest("puzzle1.xml");
var myLoader: URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(e: Event): void {
myXML = XML(e.target.data);
var answers: XMLList = myXML.children()[0].children();
var numAnswers: int = answers.length();
var i: int = 0;
var nextY = 0;
for(i = 0; i < numAnswers; i++) {
var tf_mc = new TF_MC();
addChild(tf_mc);
tf_mc.name = "tf_"+i;
tf_mc.tf.text = answers[i].toString();
tf_mc.x = 20
tf_mc.y = nextY;
nextY += tf_mc.height;
}
}
Copy link to clipboard
Copied
It worked! However, one only text box showed up.
var myXML: XML = new XML();
var myXMLURL: URLRequest = new URLRequest("puzzle.xml");
var myLoader: URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(e: Event): void {
myXML = XML(e.target.data);
var myAnswers:Sprite = new Sprite();
myAnswers.name = "answers";
answers_mc.addChild(myAnswers);
var answers: XMLList = myXML.children();
var numAnswers: int = answers.length();
var i: int = 0;
for(i = 0; i < numAnswers; i++) {
var myAns:Answer = new Answer();
myAnswers.addChild(myAns);
myAns.x = 300;
myAns.y = 400;
}
myAns.name = "text"+(i+1).toString();
}