Highlighted

External text/xml into a Dynamic Text Box

New Here ,
Apr 13, 2009

Copy link to clipboard

Copied

ive been searching for 2 days on how to do this. i would like to be "spoon fed" if at all possible, all i want to know is how to take an external text or xml file and allow AS3 to read it into a dynamic text box. i want this as to make it easier to update my website and make changes to the text bodies on each page more conveniently. thank you.

TOPICS
ActionScript

Views

1.4K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

External text/xml into a Dynamic Text Box

New Here ,
Apr 13, 2009

Copy link to clipboard

Copied

ive been searching for 2 days on how to do this. i would like to be "spoon fed" if at all possible, all i want to know is how to take an external text or xml file and allow AS3 to read it into a dynamic text box. i want this as to make it easier to update my website and make changes to the text bodies on each page more conveniently. thank you.

TOPICS
ActionScript

Views

1.4K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 13, 2009 0
New Here ,
Apr 13, 2009

Copy link to clipboard

Copied

[message removed]

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 13, 2009 0
Explorer ,
Apr 13, 2009

Copy link to clipboard

Copied

Hi,

Here you go:

var loader:URLLoader = new URLLoader();
    loader.addEventListener(Event.COMPLETE, handle_loadComplete);
    loader.load(new URLRequest("file"));

function handle_loadComplete(e:Event):void
{
    // e.target.data <- your data
    // textField.text = e.target.data
    // var xml:XML = new XML(e.target.data);
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 13, 2009 1
New Here ,
Apr 13, 2009

Copy link to clipboard

Copied

thank you!

but what is contained in the xml and is this being loaded as a file in my dir in my computer or is it from a website?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 13, 2009 0
Explorer ,
Apr 13, 2009

Copy link to clipboard

Copied

Path to the file can be "http://...file" or just "file", "myDir/file".

If XML looks like this:

<books>

     <book>

          <author>Will Smith</author>

     </book>

     <book>

          <author>Bruce Willis</author>

     </book>

</books>

then the author of the first book in a text field is:

textField.text = xml.book[0].author;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 13, 2009 1
New Here ,
Apr 13, 2009

Copy link to clipboard

Copied

thank you ... ill have to do some more reading on how to program in both languages... but you helped me emmensly! thank you very much!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 13, 2009 0
Guru ,
Apr 13, 2009

Copy link to clipboard

Copied

You should probably decide first what your requirements are first before you read a lot about xml (although it's good to learn this for sure in any case).

If you want to load a list or other structured set of data then you should use xml and may want to spend some time learning about that. This would be useful if, as in the previous example you had a list of items you wanted to load (like books as in muho_tr's example), and you wanted to load them all at once so they're available in your swf, but only wanted to display one at a time for example.

If you just want to load text from an external file into a textfield, then that's much simpler and you don't worry about the xml for now, just use the other example muho_tr showed you earlier.

function handle_loadComplete(e:Event):void
{
    textField.text = e.target.data
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 13, 2009 0
New Here ,
Apr 14, 2009

Copy link to clipboard

Copied

{edit}i just want to put external text into a textBox so all i have to do is edit the text on the external file and it will change and update unstead of going in and changing the FLA file everytime

possibly import and use the text as string variables as to put them into the textBoxes.....{/edit}

roflmao! i just realized that my Fla file was ActionScript 2.0 - ugh - i guess i will have to remake my website but use AS3 this time. i was wondering why the code was giving me errors. I would still like to know how to do this coding in AS3 tho - even if my movie is in AS2...

{edit}something you could give me a little help understanding tho. what is "e.target.data" and/or "e.Event"? now i understand that e.target.data is a var but can someone break it down and explain what it all means?{/edit}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 14, 2009 0
Explorer ,
Apr 14, 2009

Copy link to clipboard

Copied

var loader:URLLoader = new URLLoader();

    loader.addEventListener(Event.COMPLETE, handle_loadComplete);
    loader.load(new URLRequest("file"));

function handle_loadComplete(e:Event):void
{

    textField.text = e.target.data;

}

Here goes the code explanation:

addEventListener is loader's method, that means the listener targets loader. e is an instance of the event that happens after the file load is complete. URLLoader class has a property data. Since loader is an instance of URLLoader it inherits its property data, so if e is the event that targets loader, e.target.data is your data that you've just loaded.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 14, 2009 0
New Here ,
Apr 27, 2020

Copy link to clipboard

Copied

How to put this code in separate AS3 file?

Thanks

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 27, 2020 0