PDA

View Full Version : Dynamically Loading Text From an HTML Page


Mickey
11-05-2003, 12:05 PM
Hey, I'm pretty new to Flash, and I'm having trouble figuring this one out. I'm using Flash MX. I want to load the text of an HTML file into a text field in Flash when it loads so it will be easy for somebody else to just update the HTML page instead of the Flash page to make changes. I created a text field in actionscript and set the color to white and background color to black. If I just give a string to the .text property of the field everything works great. I even had success loading a text file into it. However, this is just plain unformatted text. I want to be able to load in the text from a file with HTML tags so it will look nice. However whenever I set the .html property of the text field to true everything stops working. I can't get any text to show up. Even when I pass it a string to the .htmlText property nothing happens.

So I was wondering how I get it to load HTML formatted text into the text field when I create it. I've tried creating a string variable and using the loadVariables() to load the text into that string variable and then pass its value to the .htmlText but when I trace that variable after I supposedly assign it the text with the loadVariables() it says it is undefined. So can anyone explain to me how to do this. Maybe I'm having syntax problems? Maybe I'm going about it all wrong? Maybe you can point me to a sample file that accomplishes what I'm trying to do? Anything would be appreciated.

Thanks

Ian Jones
11-05-2003, 01:51 PM
Have a look through the tutes here:

http://www.actionscript.org/tutorials.shtml

Mickey
11-05-2003, 09:22 PM
Thanks for the reply but I have checked there. They had one on loading the text files and that worked for me. But when I try to load text with HTML tags and I set the .html property on the text field to true it does not work.

Hilly
11-05-2003, 10:27 PM
when using html-encoded text you cant use the .text. You should use .htmlText instead. Hope this will solve your problems. And btw you shouldnt try to load a html document, just a html-formated txt-file.
Also not all html-tags work in flash.

Ex of formated textfile:
TheText1=<br>
<p><b>Project: </b>Cgtalk Flash</p>
<p><b>Media: </b>Website</p>
<p><b>Type: </b>Forum</p>
<p>Bla bla bla yada yad ayda</p>
<p><b>Link: </b><a href="http://www.cgtalk.com" target="_blank"> <u>www.cgtalk.com</u></a></p>

TheText1 is the variable that you load.
Here is thecode to load the html-formated text into a dynamic text box.

//dynamic text
delete myVarsObj;
// clean up old variables
this.dynTxtBox.html = true;
this.dynTxtBox.htmlText = "loading text...";
myVarsObj = new LoadVars();
myVarsObj.load("textfile.txt");
myVarsObj.onLoad = function(success) {
if (success) {
// if it did load
this.dynTxtBox.htmlText = theText1;
}
} else {
// if it didnt load
this.dynTxtBox.text = "there was an error...";
}
};
stop();
//dynamic text end
/*This is made by Mattias Kullstrand <mattias@bitbox.se> 2003

Its kind of hard to find your exact problem. Cant you post your files so I can look at them?

Mickey
11-06-2003, 04:38 AM
Thank you for your reply, I will print it out and try it at school tomorrow (they block cgTalk). If I still can't get it to work I'll email myself the files I'm working on and post them on here so you can see them. Thanks again!

Ciao

CGTalk Moderation
01-16-2006, 03:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.