PDA

View Full Version : [FMX] AS loadVars() problem



[ArcanE]
September 19th, 2003, 01:48 PM
I wanna create some sort of actionscripted typewriter which loads its content from an external file, but i can't seem to get the code to work properly!

This is what i got till now:

2 layers:
- one with a textfield called 'textbox'
- one with the actions

A textfile which contains: waarde=Wannaloadtextfromanexternaltextfile!


4 frames, in the first frame i load the textfile this way:

q = 1;
loadText = new loadVars();
loadText.load("data.txt",this);
loadText.onLoad = function(success) {
if (success) {
trace(this.waarde);
text = this.waarde;
} else {
trace("Error");
}
};

In the second frame is the typewriter code, pretty straigtforward:
if (q < text.length) {
textbox = text.substring(0, q);
q++
} else {
textbox = text;
gotoAndStop(4);
}

And the third frame just loops back to the second for the typewriter effect.

Fourth frame is empty


The problem is that when i assign the value of "text" in the first frame this way : <-- text = "Wannaloadtextfromanexternaltextfile!"; --> (witout the comment tags ofcourse) the typewriter works fine but when i load the var from the textfile nothing happens, the trace works fine and displays the contents of the var but the typewriter displays nothing.

the weird this is that when i add this after all the code in frame 1 it works fine: text = "azerty";
But when i add this it doesn't: text = "a";

So when i overwrite the var with the azerty value suddenly it contains the correct value in the next frame, when i assign only one character to it the script doesn't work anymore. Some weird **** here :o


I included the code for you guys to look at!

I hope someone can help me out here.

claudio
September 19th, 2003, 04:18 PM
I dont have flash now and im late for school, but try this:loadText = new LoadVars();
loadText.onLoad = function(success) {
if (success) {
content = this.myVar;
//myVar is the variable inside the txt file
}
};
loadText.load("data.txt");
//external txt file
type = 0;
this.createEmptyMovieClip("holder", 1000);
holder.onEnterFrame = function() {
if (content.length>0) {
type>content.length ? this.onEnterFrame=null : mytext=content.substr(0, type++);
//myText is the variable associated with the textfield
}

};

[ArcanE]
September 20th, 2003, 09:09 AM
Works like a charm! perfect, thanks alot claudio,

But still, i'm riddled why the code i wrote doesn't work ... and as eager to learn i am i always wanna know what went wrong?

Anyone ?

[ArcanE]
September 22nd, 2003, 10:46 AM
Bump

Another one:

loadText = new LoadVars();
loadText.onLoad = function(success) {
if (success) {
image = this.img1;
datatext = this.text1;
}
};
loadText.load("data.txt");
jpgholder.loadMovie(image + ".jpg");

Why is the image var empty??

The script returns an error that "file:///C|/Documents%20and%20Settings/Admin/Bureaublad/test/.jpg" cannot be found??

claudio
September 22nd, 2003, 11:03 AM
Try:loadText = new LoadVars();
loadText.onLoad = function(success) {
if (success) {
datatext = this.text1;
jpgholder.loadMovie(this.img1+".jpg");
}
};
loadText.load("data.txt");

[ArcanE]
September 22nd, 2003, 01:33 PM
Still no good :(

The error is gone but the image doesn't load, even not when i remove the variable and put jpgholder.loadMovie("foto1.jpg"); inthere

weird,

I attached the source for you guys to look at ;)