0

I have a xml file with 100+ text entries in it and a dynamic textfield. I would like the text to change depending on the frame number. Here is my (non-working) code:

var myXML5: XML = new XML();
var XML_URL5: String = "assets/bulles.xml";
var myXMLURL5: URLRequest = new URLRequest(XML_URL5);
var myLoader5: URLLoader = new URLLoader(myXMLURL5);
myLoader5.addEventListener("complete", xmlLoaded5);
var list5: Number = 0;

function xmlLoaded5(event: Event): void {
myXML5 = XML(myLoader5.data);
}

function fnPeople5(peopleList5: XML): void {
bulles.text = peopleList5.bullestext.bulle.text()[list5];
}


function bulles2(e: Event): void {
var i5: int = france_map.currentFrame();
list5 = i5;
fnPeople5(myXML5);
}

I hope someone can help :) Jeryl

Jeryl
  • 139
  • 1
  • 10
  • can you add xml structure to description please ? – Bartosz Jul 06 '14 at 12:14
  • get any errors? result of traces? notably `trace(peopleList5.bullestext.bulle.text()[list5])` in `fnPeople5` – golyo Jul 06 '14 at 12:14
  • bejrut: text text2 (i'm a beginner so i don't know if it's correct or not, but it worked in another mini-app i made) – Jeryl Jul 06 '14 at 12:22
  • @MartonPallagi No errors, the rest of the app works fine, but no text appears in the textfield. I've added the trace part in fnPeople5 and i've no result. – Jeryl Jul 06 '14 at 12:26

1 Answers1

0

This should give you an idea. Assuming your xml is something like this

<?xml version="1.0" encoding="UTF-8"?>

<myTexts>

<bullestext> <bulle> text1a </bulle> </bullestext> <bullestext> <bulle> text2b </bulle> </bullestext> <bullestext> <bulle> text3c </bulle> </bullestext> <bullestext> <bulle> text4d </bulle> </bullestext> <bullestext> <bulle> text5e </bulle> </bullestext>

</myTexts>

then you can do your code like this..

var myXML5: XML = new XML();
var XML_URL5: String = "assets/bulles.xml";
var myXMLURL5: URLRequest = new URLRequest(XML_URL5);
var myLoader5: URLLoader = new URLLoader(myXMLURL5);
myLoader5.addEventListener("complete", xmlLoaded5);
var list5: Number = 0;

function xmlLoaded5(event: Event): void 
{
    trace ("XML loaded complete");
    myXML5 = XML(myLoader5.data);
    //trace (myXML5); ///show xml contents

    //fnPeople5(myXML5); 
    france_map.gotoAndStop(3); //for test (shows xml entry [3] later on)
    bulles2();
}

//testing without event (click event?)
//function bulles2(e: Event): void 
function bulles2(): void 
{
    var i5: int = france_map.currentFrame;   //.currentFrame();
    list5 = i5 - 1; //frame [1] is equal to xml entry [0] so we minus by 1
    trace ("list5 : " + list5);
    fnPeople5(myXML5);
}

function fnPeople5(peopleList5: XML): void 
{
    //testing traces
    trace(peopleList5.bullestext[0].bulle);
    trace(peopleList5.bullestext[4].bulle);

    //show entry (example: entry 3) 
    bulles.text = peopleList5.bullestext[list5].bulle;
}


I didn't setup a mouse/keyboard event for testing but no worries, nothing wrong with what you had before so you can still use function bulles2(e: Event): void with your own full code. Also because XML counts from zero but frame count is from one we know that every XML entry equals Frame number minus one less.

If text doesn't show in the textField but works ok with trace in fnPeople5(peopleList5: XML): void then try embedding font. Check this link: What methods are there for creating FLAs with dynamically created text, that outputs swfs with only the font glyphs included that are required?

Community
  • 1
  • 1
VC.One
  • 14,790
  • 4
  • 25
  • 57
  • I tried your code (i adapted the xml to your proposed structure), and I have this error : – Jeryl Jul 07 '14 at 05:29
  • TypeError: Error #1090: XML parser failure: element is malformed. at france_fla::MainTimeline/xmlLoaded5() [france_fla.MainTimeline::frame1:994] at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/onComplete() – Jeryl Jul 07 '14 at 05:30
  • There's nothing on frame 994, but i might know why it did an error. My timeline is a real timeline (a frame = a year). It starts at 3000bc and ends at 2014ad. frame 1 = 1bc, frame 3000 = 3000bc, frame 3001 = 1ad. frame 5014 = 2014ad. This part of the app does'nt start at 3000bc, but at 60bc, so frames 61 to 3000 are empty. In my xml, the 60 first frames correspond to an entry, but frames 61 to 5014 are empty (i'm searching for a way to "skip" entries 61 to 3000 in the xml file). The missing entries might be why there's this error? Anyway thanks a lot for this complete and clear answer. – Jeryl Jul 07 '14 at 05:36
  • `[france_fla.MainTimeline::frame1:994]` means the `Error is from frame1 code & caused by line 994`. The malformed part I suspect is you put a space in the `` names? For quick example: `` is malformed but `` is okay or even ``. The content `text1a` can have spaces though so `te xt 1 a` is fine so just the `` parts are sensitive about having spaces. – VC.One Jul 07 '14 at 16:04
  • PS: for skipping entries consider the `//testing traces` code in last function of posted code. It checks 1st [0] and 5th [4] items in xml so it already skipped items 2,3 & 4. Thats the general idea of how to skip index positions you dont want.. dont "use" them. – VC.One Jul 07 '14 at 18:08
  • you were right, the errror was due to a space in the ! Sadly, the xml data still doesn't show in the textField nor in the trace. Basically, it seems like that part of the code doesn't exist and does nothing :s. Do you know another approach I could look into? I really appreciate your help. – Jeryl Jul 08 '14 at 12:25
  • Can you update your post with a short sample of your XML file (copy everything from 1st top line to maybe 5 entries and close tags). Also update your posted code with your function that tries to show XML entries. Need to see what you read & how you're reading it – VC.One Jul 08 '14 at 13:19
  • i'm not on my hom computer right now. I'll update tonight. Thanks. – Jeryl Jul 08 '14 at 13:34
  • hum, it works now. I just called the function with the wrong button... Just me being a noob I guess! Again I thank you and validate your answer! :) – Jeryl Jul 09 '14 at 05:34
  • if i may ask, for the skipping entries (xml), you said to use //testing trace code. Could you explain, please? Because I'm not sure I understood. Thanks – Jeryl Jul 09 '14 at 05:37
  • I meant use it as a learning example. `trace ( peopleList5.bullestext[4].bulle );` just means use 5th index position from zero. Hence [0] traces first xml entry. To skip specific xml entries simply dont use their specific index positions. For example: To "skip from 61 to 3000" and trace only entry 60 and entry 3001 from xml file.. `trace ( peopleList5.bullestext[60].bulle ); trace ( peopleList5.bullestext[3001].bulle );` – VC.One Jul 09 '14 at 18:54