Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help w/ text variable issue

Status
Not open for further replies.

TMac42

Programmer
Jul 24, 2000
83
US
I've got a small app that reads the contents of a text file and then displays those contents on a Flash banner. The text file reads: Test=This is a test.

Here's the problem: I can read the contents of the text file but for some reason it won't display on the banner. If I hard code the value of the string in place of this.Text.toString, to something like say... "TEST", for example, my banner scrolls "TEST" just as it should. So, it's like I'm 80% of the way there but need help sorting out why the banner's not getting the dynamic value it needs.

If I trace this.Text.ToString() right before the call to placeText, the value displayed is correct - just like it reads in the text file, so I think it's getting passed properly. Thoughts?? Thanks.

Code:
function placeText(target:MovieClip, x:Number, y:Number, banner:String, tFormat:TextFormat, effectFunction:Function, delay:Number):Void {
	// For each character...
	for (var i = 0; i<banner.length; i++) {
		// Create a clip and place the current
		// character in the text field inside it.
		var char:MovieClip = target.attachMovie("letter", "char"+i, target.getNextHighestDepth());
		char.field.text = banner.substr(i, 1);
		char._x = x;
		char._y = y;
		// Add the width of the current text character to the
		// next letter's x position.
		x += tFormat.getTextExtent(char.field.text).width;
		//
		// Here is the effect function call, passed in as a parameter
		effectFunction(char, i*delay);
	}

var my_lv:LoadVars = new LoadVars();
my_lv.onLoad = function(success:Boolean) {
    if (success) {
		var format:TextFormat = new TextFormat();
		format.font = "Verdana";
		format.size = 14;
		trace(this.Text.toString());
		placeText(this, 7.5, 1, this.Text.toString(), format, fadeZoom, 100);
    } else {
    	//trace("Error loading/parsing LoadVars.");
    }
};
my_lv.load("ExampleFlashTextFile.txt");
 
I see few typos in your code.

In the first function the closing "}" is missing.

In "my_lv.onLoad" function, "this.Text.toString()" needs to be "this.Test.toString()".

Also "placeText(this, 7.5, 1, this.Text.toString(), format, fadeZoom, 100)" needs to be "placeText(_root, 7.5, 1, this.Text.toString(), format, fadeZoom, 100)".
I know it's ugly to use "_root" but you cannot refer "this" here, as "this" means LoadVars object and you cannot attach movie clips to it!
(You can modify the code to avoid the use of "_root" easily though.)

It should now look:

[tt]//
var my_lv:LoadVars = new LoadVars();
my_lv.onLoad = function(success:Boolean) {
if (success) {
var format:TextFormat = new TextFormat();
format.font = "Verdana";
format.size = 14;
trace(this.Test.toString());
placeText(_root, 7.5, 1, this.Test.toString(), format, fadeZoom, 100);
} else {
//trace("Error loading/parsing LoadVars.");
}
};
my_lv.load("ExampleFlashTextFile.txt");
//[/tt]

Kenneth Kawamoto
 
Thanks for the help. I get "undefined" in my Output window. If I change this.Test.toString() to be "TEST", my text comes out on the page fine - "TEST". So, it's still just an issue of it holding the value from the text file.
 
Found my problem - the text file was "Text=", not "Test=" Grrr. Thanks so much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top