A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: XML data from one XML file into two different dynamic text fields - AS3

  1. #1
    Junior Member
    Join Date
    Sep 2015
    Posts
    6

    XML data from one XML file into two different dynamic text fields - AS3

    I am new to Flash and ActionScript 3 and have been struggling with this all day and searched forums, tutorials and everywhere, but unable to solve my problem.

    In my fla I have 3 frames.

    In flame 3: I have 9 movieclips. On mouse click each movieclip loads text into a dynamic text field with the instance name ‘object_txt’. In the xml, each text has a section with the same name as the movieclip it belongs to (like this: <object1_mc>). This works perfectly, and all the texts are loading.

    The code:

    // Load text for the objects
    object_txt.styleSheet = css;
    stage.addChild(object_txt);

    object_txt.htmlText = langData[language][objectPressed.name];

    Now here is my problem:

    In frame 2: I want to load a section from the same xml into a text field with the instance name of ‘history_txt’ when I enter this frame (only in this frame)
    The section in the xml has the section name: <history_txt>

    I have the URL loader in frame 2:

    // URL loader for texts:
    var urlr:URLRequest = new URLRequest("local.xml");
    var loader: URLLoader = new URLLoader(urlr);
    loader.addEventListener(Event.COMPLETE, completeHandler);

    var langData:XML;

    function completeHandler(event: Event): void
    {
    var loadedText: URLLoader = URLLoader(event.target);
    langData = new XML(loadedText.data);
    }
    // Make a stylesheet for texts:
    var css: StyleSheet = new StyleSheet();
    css.parseCSS('h1 { color: #99CCFF; font-weight: bold; font-size: 68px; } p {font-size: 30px;}');

    stage.addChild(history_txt);
    history_txt.styleSheet = css;
    history_txt.htmlText = langData[language] ? ; // I don’t know how to get the section from the xml

    Could someone help me with this? Any help would be appreciated!

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Attach your *.fla and *.xml files as it will make it easier for us/me to help you, save trying to recreate your files.

  3. #3
    Junior Member
    Join Date
    Sep 2015
    Posts
    6
    Thank you for your answer, fruitbeard!

    I don't want to attach the fla because it is very heavy because of the images (It is not going to be online, just stored locally, so the size doesn't matter).

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    HI,

    Make a copy and remove the images and sound files , or make a skeleton file and attach the *.fla and xml files.

  5. #5
    Junior Member
    Join Date
    Sep 2015
    Posts
    6
    I'm sorry, but I am unable to upload the fla file (or the xml). I tried again and again, but I can't upload them. The xml is not even selectable

  6. #6
    Junior Member
    Join Date
    Sep 2015
    Posts
    6
    test_copy.fla

    I reduced the file size even more, so here it is now.

    Still unable to upload the xml - sorry!

    My comments are in frame 2, line 48-54

    NB: The code is really bad, but I am trying to learn.
    Last edited by kodelina; 09-06-2015 at 07:56 AM.

  7. #7
    Junior Member
    Join Date
    Sep 2015
    Posts
    6
    I made an example of how the xml (local.xml) is structured (I just removed the texts for most of the movieclips):

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

    <en>
    <history_txt>
    <![CDATA[
    <h1>bla bla</h1>
    <p>bla bla</p>
    ]]>
    </history_txt>
    <coffee_mc>
    <![CDATA[
    <h1>bla bla</h1>
    <p>bla bla</p>
    ]]>
    </coffee_mc>
    <keg_mc>
    <![CDATA[
    <h1>bla bla</h1>
    <p>bla bla</p>
    ]]>
    </keg_mc>
    <rope_mc>
    <![CDATA[
    <h1>bla bla</h1>
    <p>bla bla</p>
    ]]>
    </rope_mc>
    </en>

    <no>
    <history_txt>
    <![CDATA[
    <h1>bla bla</h1>
    <p>bla bla</p>
    ]]>
    </history_txt>
    <coffee_mc>
    <![CDATA[
    <h1>bla bla</h1>
    <p>bla bla</p>
    ]]>
    </coffee_mc>
    <keg_mc>
    <![CDATA[
    <h1>bla bla</h1>
    <p>bla bla</p>
    ]]>
    </keg_mc>
    <rope_mc>
    <![CDATA[
    <h1>bla bla</h1>
    <p>bla bla</p>
    ]]>
    </rope_mc>
    </no>

    </data>

  8. #8
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    The file is doone in Flash CC, it did however let me open it (I use CS6), it is full of errors from the start (lots of Undefined properties).
    If you make a skeleton file with just the textfields and relevant buttons and frames then I can try to help you.

  9. #9
    Junior Member
    Join Date
    Sep 2015
    Posts
    6
    Thanks for trying to help me out, but then I'd have to include the movieclips, and the file would be too heavy to upload. The movieclips are loading the texts (from local.xml) in frame 3, so the fla would be useless without them...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center