Forums: Flash:

 

as2 - controlling timeline with variables loaded into dynamic text field

first
 

arigato as2 - controlling timeline with variables loaded into dynamic text field

So, basically I need to create a toggle.

I created a dynamic textfield named "alert", with the variable as "alert'.

I then created a text file named "alert.txt" simply containing the following:

alert=red


I have a label on frame 2, "red".

Here's the actions I have on my timeline:
stop();
urlLoadVar = new LoadVars();
urlLoadVar.load("alert.txt");
urlLoadVar.onLoad = function (success){
if (success == true) {
alert.text=urlLoadVar.alert;
gotoAndStop(alert);

}
}


The text field does indeed display "red" but it don't go. Thoughts?

 

DontBogartMe

yup, try:

gotoAndStop(urlLoadVar.alert);

- you missed the "urlLoadVar." bit out.

 

arigato

like this?

stop();
urlLoadVar = new LoadVars();
urlLoadVar.load("alert.txt");
urlLoadVar.onLoad = function (success){
if (success == true) {
alert.text=urlLoadVar.alert;
gotoAndStop(urlLoadVar.alert);

}
}


That doesn't work either.

I also tried
stop();
urlLoadVar = new LoadVars();
urlLoadVar.load("alert.txt");
urlLoadVar.onLoad = function (success){
if (success == true) {
alert.text=urlLoadVar.alert;
gotoAndStop("urlLoadVar.alert");

}
}

to no avail.

as a test I tried
stop();
urlLoadVar = new LoadVars();
urlLoadVar.load("alert.txt");
urlLoadVar.onLoad = function (success){
if (success == true) {
alert.text=urlLoadVar.alert;
gotoAndStop("red");

}
}


Which does indeed go to the correct label.

 

DontBogartMe

you know why this didn't work right?
gotoAndStop("urlLoadVar.alert");

cos the quotes around it tell Flash that it's a string - so just take it as it is. If you remove the quotes as you should, it tells Flash that it's a variable, in other words "give me whatever value the variable urlLoadVar.alert has right now". Which should be "red" of course... but isn't.

I'm stabbing a wild guess myself now TBH, but try this concoction:

gotoAndStop(urlLoadVar.alert.toString());

and also add

trace("urlLoadVar.alert.toString() = " + urlLoadVar.alert.toString());
to see what it really equates to.

 

arigato

It traces

urlLoadVar.alert.toString() = red

Which seems correct, no? But still the frame does not advance.

 

DontBogartMe

have you got a carriage return or any other whitespace at the end of your text file? I tested it here, and it worked fine. Then I added a carriage return and it broke the way you described.

 

DontBogartMe

you can also end it like this:

alert=red&

with that extra ampersand, since that's the separating character it isn't read in as part of the value of "alert", and having it there means that if you do accidentally add whitespace, it won't mess up your app.

 

arigato

Noice, that was exactly the problem. Thanks again, you're a gentleman and a scholar.

 

DontBogartMe

alert=red&


whatever


even that junk worked fine smile

 

DontBogartMe

no prob

 
first
 

Forums: Flash: as2 - controlling timeline with variables loaded into dynamic text field

 
New Post
 
You must be logged in to post