A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: loading XML into dynamic text box

  1. #1
    Member
    Join Date
    May 2001
    Posts
    37

    loading XML into dynamic text box

    I'm still in the beginner's stage of learning AS 3.0, so bear with me...

    I've got a very simple file with a dynamic text box that I want an external XML file to load into. I know I'm missing one piece in the code following, but I don't know what it is. Any help is appreciated. thanks.

    (fyi, the instance name of the text box is "output_txt" and the XML file is "articleInformation.xml")

    //This creates a new instance of the URLrequest object with
    //the path to the XML file.
    var my_req:URLRequest=new URLRequest("articleInformation.xml");
    //This creates a new instance of the loader object.
    var my_loader:URLLoader = new URLLoader();
    //The XML is saved in the variable my_xml.
    var my_xml:XML;
    //Event listener to listen to when the XML file has finised loading.
    my_loader.addEventListener(Event.COMPLETE, xmlLoader);
    my_loader.load(my_req);
    function xmlLoader(event:Event):void {
    //This parses the XML data.
    my_xml=new XML(my_loader.data);
    setupoutput_txt();
    }
    }

  2. #2
    Junior Member
    Join Date
    Jun 2010
    Location
    San Diego, CA
    Posts
    13
    I'm attaching of a working example of your code.
    Attached Files Attached Files

  3. #3
    Animal Flasher RobbieC's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    242
    That is great, I've been trying to get my head 'round a similar problem...

    How do I get this to work with multiple (ie. 3) textboxes and seperate strings in xml?

    xml:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <boardContent> 
    	<boardTitle>Main Title</boardTitle> 
    	<boardDesc>blah blah blah</boardText> 
    	<boardColor>red</boardTitle> 
    </boardContent>
    My 3 dynamic text boxes are called: title_txt, desc_txt & color_txt

    Any help would be gratefully received

    Thanks in advance

  4. #4
    Junior Member
    Join Date
    Jun 2010
    Location
    San Diego, CA
    Posts
    13
    Hey RobbieC,
    I just amended the prior code to be able to parse your xml. All you have to do is paste in this code on the demo above and be sure to add in your textfields.

    Actionscript Code:
    var my_req:URLRequest=new URLRequest("articleInformation.xml"); //PUT IN YOUR XML SOURCE HERE
    var my_loader:URLLoader = new URLLoader();
    var my_xml:XML;

    my_loader.addEventListener(Event.COMPLETE, xmlLoader);
    my_loader.load(my_req);

    function xmlLoader(event:Event):void {
        my_xml=new XML(my_loader.data);
       
        setupoutput_txt();
    }

    function setupoutput_txt():void{
        trace(my_xml.*);
        title_txt.text=String(my_xml.boardTitle.*);
        desc_txt.text=String(my_xml.boardDesc.*);
        color_txt.text=String(my_xml.boardColor.*);
    }

  5. #5
    Animal Flasher RobbieC's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    242
    Awesome stuff Prof, thanks very much!!!

  6. #6
    Junior Member
    Join Date
    Jul 2010
    Posts
    4
    hey guys i manage to do the above thing but my problem is that it only shows some part of the text. what i mean is that on the dynamic textbox its suppose to display "article one" but what it does is only display "ee e"
    what is causing this?

  7. #7
    Junior Member
    Join Date
    Jun 2010
    Location
    San Diego, CA
    Posts
    13
    This could be a result of not embedding certain characters of the particular font you are using.

    Try this:
    1. Click on the dynamic textbox.
    2. In the PROPERTIES window you should see a section called "CHARACTER". Click on "Character Embedding..."
    3. Select "All" and hit okay. If you are worried about file size, then you should select individual characters sets to embed.
    4. Test that out and let me know if that solves your issue.

  8. #8
    Junior Member
    Join Date
    Jul 2010
    Posts
    4
    hello professor;

    hihihih nice name, anyway yes i did try what you told me and it works, yet your right again embedding creates an issue on the file size. would you tell me what fonts do not need to be embedded?

    thanks a lot for the replies.

  9. #9
    Junior Member
    Join Date
    Jun 2010
    Location
    San Diego, CA
    Posts
    13
    You only need to embed the font you want to use for that particular dynamic text field. System fonts such as Arial or Times New Roman don't necessarily need to be embedded since these are common fonts. You can find a list of common fonts here

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