Skip to main content
November 29, 2006
Question

refreshing without looping???

  • November 29, 2006
  • 41 replies
  • 2635 views
Hello everyone - i am trying to build something using mostly code but i am having a SERIOUS issue with the fact that i can only get it to work properly if i have it spanning 2 frames with my code on the first, and code on frame 2 simply "gotoAndPlay(1);" to loop it so my script keeps being rechecked for changes in variables. Because i have things trigger when variables change...heres what i mean.

if(_global.logged=="true"&&faded==false){
new Tween(usr_matt, "_alpha", Strong.easeOut, 100, 0, 2, true);
faded==true;
}

which should trigger when a loaded swf sets the global logged variable to true. But unless i loop the timeline to keep checking the variables nothing happens because it doesnt know its changed, it doesnt watch/listen to it. the problem with this in this case is everytime the timeline loops it reinitilizes that if statement and starts the tween all over again, meaning it never fades because it keeps restarting the fade!

another example being -

if (usr_name.text=="Matt"&&usr_pass.text=="test"){
submit.enabled=true
}else{
submit.enabled=false
}

here i disable the submit button until the fields match, so again i needed to loop the timeline to keep the variables updating to see when the fields did match! unfortunatly that messed up the next bit of code so i had to impliment a work around for it

if(init<=1){
usr_name.text = des_usr;
init=3
}

where i have a text field that inherits its .text value initially from a global variable, but then in order (just in case) the user wants to change the value (if they dont like the default) i needed to break to loop by making a whole new variable to cancel it out once its been triggered once!

My head is just starting to hurt with ALL the variables im assinging and i havnt really even dont anything yet but make a popup box and pass some variables...but christ...i cant have every timeline on a loop that would bog everything down SO much, eventually i will have 4-5 loaded swf's on at once, all looping? i dont think so...

There HAS to be a better way to do it, to assing certain If statements to constatly update without looping the whole damn thing!

--][--
This topic has been closed for replies.

41 replies

November 30, 2006
its very possible im just completly naf and missing something stupid here...but i just cant seem to figure it out :S
November 30, 2006
kglad
Community Expert
Community Expert
November 30, 2006
you have a button or movieclip on-stage with instance name submit when that code executes? if so, post a link to your fla.
November 30, 2006
usr_name.variable=usrNameVar;
usr_pass.variable=usrPassVar;

loginCheck = function (prop, oldVal, newVal) {
if (usrNameVar == "Matt" && usrPassVar == "test") {
submit.enabled = true;
} else {
submit.enabled = false;
}
return newVal;
};
watch("usrNameVar", loginCheck);
watch("usrPassVar", loginCheck);

does absolutly nothing...doesnt disable the box or anything...
November 30, 2006
gosh im a moron - i knew that as well, grrr. sorry kglad. You've been a real help here I appreciate it!
November 29, 2006
okay next question - how am i appending the text fields .text property to the variables usrNameVar - usrPassVar? because again - it wont update the variable while i type, only when its reloaded...so...are we not just back to where we started?
kglad
Community Expert
Community Expert
November 30, 2006
if your textfields are created in the authoring environment check the properties panel. there's a Var: input region where you can enter a variable name. or you can use the variable property of textfields to add the variable name using actionscript.

for example:



November 29, 2006
Ah well you just answered my next question - i was going to say can i not just get it to watch the .text property instead of putting it to a variable first. No matter though i think i can sort that out. by different functions you do mean

loginCheck = function (prop, oldVal, newVal

changing the loginCheck name right? by the way what are the handlers on there? prop, oldVal, newVal - what are they each doing?

cheers!
kglad
Community Expert
Community Expert
November 29, 2006
yes. you will probably want to use different functions for the various tasks, but any variable can be watched.

object properties can be watched, too but i had trouble setting up a watch method for the text property of a textfield. that's why i resorted to using a variable associated with a textfield.
November 29, 2006
I will give that a go - sounds promising! and i should be able to do that for all my vars?
November 29, 2006
thank you kglad for the quick response! would you mind just a quick "how" say with one of the example i provided that would be great! obviously i have never heard of the watch function and it sounds like exactly what im looking for!, again - thank you!
kglad
Community Expert
Community Expert
November 29, 2006
if you associate variables with your textfields, you can use: