1 2 Previous Next 52 Replies Latest reply on Dec 3, 2006 9:01 AM by kglad

    refreshing without looping???

    ][odine
      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!

      --][--
        • 1. Re: refreshing without looping???
          kglad Adobe Community Professional & MVP
          you can use the watch() function to check when variables change and trigger actions when they do.
          • 2. Re: refreshing without looping???
            ][odine Level 1
            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!
            • 3. Re: refreshing without looping???
              kglad Adobe Community Professional & MVP
              if you associate variables with your textfields, you can use:

              • 4. Re: refreshing without looping???
                ][odine Level 1
                I will give that a go - sounds promising! and i should be able to do that for all my vars?
                • 5. Re: refreshing without looping???
                  kglad Adobe Community Professional & MVP
                  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.
                  • 6. Re: refreshing without looping???
                    ][odine Level 1
                    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!
                    • 7. Re: refreshing without looping???
                      ][odine Level 1
                      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?
                      • 8. Re: refreshing without looping???
                        kglad Adobe Community Professional & MVP
                        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:



                        • 9. Re: refreshing without looping???
                          ][odine Level 1
                          gosh im a moron - i knew that as well, grrr. sorry kglad. You've been a real help here I appreciate it!
                          • 10. Re: refreshing without looping???
                            ][odine Level 1
                            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...
                            • 11. Re: refreshing without looping???
                              kglad Adobe Community Professional & MVP
                              you have a button or movieclip on-stage with instance name submit when that code executes? if so, post a link to your fla.
                              • 13. Re: refreshing without looping???
                                ][odine Level 1
                                its very possible im just completly naf and missing something stupid here...but i just cant seem to figure it out :S
                                • 14. Re: refreshing without looping???
                                  kglad Adobe Community Professional & MVP
                                  the dreaded components. you're using a textinput component. that's not the same as an input textfield. in particular, there's no variable associated with a textinput component.

                                  anyway, here's a working version of your login.fla. i did not edit desktop.fla:

                                  www.gladstien.com/new/login.fla
                                  • 15. Re: refreshing without looping???
                                    ][odine Level 1
                                    Thank you so much kglad - truely a god amoungst mortals. if you dont mind me asking - did you have messenger or anything like that?

                                    as well - the last line of code "submit.enabled = 0" where/what is that doing? the rest is beautiful!
                                    • 16. Re: refreshing without looping???
                                      kglad Adobe Community Professional & MVP
                                      the last line is to make the submit button disabled by default. it's only enabled when the correct user name/pass are entered. that code can be removed.

                                      p.s. i have no messenger clients. i have an email link at my website:

                                      www.gladstien.com
                                      • 17. Re: refreshing without looping???
                                        ][odine Level 1
                                        Okay I Do appreciate all you have don VERY much, and you are by no means obligated to help me any further if you dont wish, please dont think i am just tryig to get you to do this i really am trying to learn here. I have tried to bring what you did over to my desktop.fla. I was trying to set it up so when you logged in, the variable "_global.logged_usr" would represent who logged in, it would then be collected by the desktop.fla and do a little animation thing. I did this:

                                        log = new Object();
                                        log.change = function(eventObject:Object) {
                                        if (_global.logged_usr.text.toLowerCase() == "matt") {
                                        trace("established");
                                        new Tween(usr_matt, "_alpha", Strong.easeIn, 100, 0, 3, true);
                                        }
                                        }

                                        logged_usr.addEventListener("change", log);

                                        I get no response from the trace so its not even getting to that point. anyideas where i have gone wrong? it looks fine to me based on what we did in the previous movie. and we cant blame components this time neither! lol.
                                        • 18. Re: refreshing without looping???
                                          kglad Adobe Community Professional & MVP
                                          you shouldn't prefix a variable name with _global (or var) unless you are assigning a value to it. when you're retrieving a value, the prefix should not be used.

                                          so, in login.fla you correctly use

                                          _global.logged_usr = usr_name.text;

                                          removing the _global prefix from desktop.fla may be all you need to do. but if that doesn't work, then i'll need to know how these two swfs are related.

                                          for example, do you use loadMovieNum() to load one of them?
                                          • 19. Re: refreshing without looping???
                                            ][odine Level 1
                                            // Create window.
                                            var my_win:MovieClip = PopUpManager.createPopUp(this, Window, true, {title:"Please Login", closeButton:true, contentPath:"login.swf"});
                                            var winListener:Object = new Object();
                                            winListener.click = function() {
                                            my_win.deletePopUp();
                                            };
                                            my_win.addEventListener("click", winListener);
                                            my_win.setSize(350, 163);
                                            my_win.move(200, 150);
                                            }
                                            • 20. Re: refreshing without looping???
                                              kglad Adobe Community Professional & MVP
                                              oh no, another component.

                                              but using _global in login.fla saves us from using the path _level0.depthChild0.content to your popup. so, the problem isn't the path, it's your attempt to attach a listener to a variable which has some problems.

                                              there's a more direct solution in this situation: you can call a function in your desktop.fla from your submit button in login.fla:

                                              • 21. Re: refreshing without looping???
                                                ][odine Level 1
                                                Hey kglad, once again - you are my savior lol.

                                                I have been making some progress (even though im sure im doig it all wrong!)

                                                I have run into an issue, i am not trying to add more sets of usernames and passwords to what we alreayd have, unfotunatly its not like i can just add another if statement to the mix, or append whats there with a ||. So again, i am at a loss, no matter what i do it seems to just accept the last once i entered and completly ignores the rest. Thoughts?
                                                • 22. Re: refreshing without looping???
                                                  ][odine Level 1
                                                  I guess i could copy the lo. change function 5 times...i dont know if that would work...and it certainly doesnt seem practicle, im still have a problem with it taking the most recently added username/pass. I cant see any other way of adding the other than "||" after the first pair really. thoughts?

                                                  --][--
                                                  • 23. Re: refreshing without looping???
                                                    Flash2KoolForSkool
                                                    Do you have any experience with php/mySQL?

                                                    It sounds like you could use a database to store all of the login data and use php to check if the data entered into the flash form exists in the database , then if it does return yes and if it doesn't return no.

                                                    The do whatever is required after the login depending on the php return.

                                                    • 24. Re: refreshing without looping???
                                                      ][odine Level 1
                                                      Indeed i have seen such options - and to be completly honest that seems beyond the scope of what Im trying to do. If i was doing this for a more serious project and needed expandability and such i would ceratinly try to utilize php/mySQL. Fortunatly/unfortunatly this has just been an idea I started off with that has grown (couldnt have gotten where i am now though without kglads help, hes been great! - But thank you flash2koolforskool, i appreciate the thought!

                                                      Still having the issues though with the system i have now, for those who dont know...
                                                      [code]
                                                      lo.change = function(eventObject:Object) {
                                                      if (usr_name.text.toLowerCase() == "matt" && usr_pass.text.toLowerCase() == "test") {
                                                      submit.enabled = true;
                                                      } else {
                                                      submit.enabled = false;
                                                      }
                                                      }
                                                      };
                                                      [/code]
                                                      is what im using, and i need to somehow get more possible usernames and passowrd in there! not many! just 4 more. ideas?!

                                                      --][--
                                                      • 25. Re: refreshing without looping???
                                                        kglad Adobe Community Professional & MVP
                                                        you can list all your username/password combinations in an array and loop through the array to check if a correct login is recognized.

                                                        but before you go much further, how secure is this supposed to be?
                                                        • 26. refreshing without looping???
                                                          ][odine Level 1
                                                          not very at all! i mean, not in the least would probably be a better way of putting it!

                                                          I would actually considering redoing this all at some point using php/mySQL as suggested in the future - and that will be more secure, but for now, this is MORE than enough for sure.

                                                          next thing would be - how on earth do we define all the usrnames and passwrds in a looping array??! im all ears.

                                                          p.s. thank you for comming back! lol.
                                                          --][--
                                                          • 27. Re: refreshing without looping???
                                                            kglad Adobe Community Professional & MVP
                                                            you just need to keep adding [username,passwords] to usrA to authorize more users.

                                                            • 28. Re: refreshing without looping???
                                                              ][odine Level 1
                                                              Kglad that works like a dream! a very clever use of the array there i will certainly have to remember that! (its not very secure though you say?)

                                                              Okay your going to laugh at me im sure...but i have attatched my code for "desktop.fla" as well as what i got currently for "login.fla" it seems when the button is fired it triggers the the wrong movieclip....as you can see from the code I attatched it works flawleslly with just the 1 MC on the stage coded. But as soon as i add the next one "under the //----ryan---- comment line - no matter who i login be it matt or ryan it fires ryans animations. I have 3 more to add after ryan and i tried it and in the case when all 5 are in, no matter who i login is it fires the last one all the time. I am sure it has something to do with my code structure, i have just been copying the first MC's code and changing the references to it, to the new one as i go...you will see...what have i done wrong? i know its a Sod.
                                                              • 29. Re: refreshing without looping???
                                                                kglad Adobe Community Professional & MVP
                                                                i'll let you know how to simplify that when i get back from work. gotta go see patients.
                                                                • 30. Re: refreshing without looping???
                                                                  ][odine Level 1
                                                                  kglad I really cannot thank you enough. Honestly! i was going to give you an email but i was wearing of just using that flash form (didnt know when/if you would get it) Again - thank you so much! i have always been able to use flash and write code, not well by any means, but your really helping me take it to the next level for me and thats great because i love this stuff! Thank you again!

                                                                  --][--
                                                                  • 31. Re: refreshing without looping???
                                                                    kglad Adobe Community Professional & MVP
                                                                    i removed usrA from login.fla. otherwise the following code includes all the coding needed no matter how many users you add to usrA.

                                                                    • 32. refreshing without looping???
                                                                      ][odine Level 1
                                                                      Hey kglad - thank you SO much for that! I am doing my best to look it all over and see what you have done to tidy it up! looks so much cleaner!....but....it doesnt work. Im sure its hard writing the code without knowing how it will work lol, you've done amazing! i provided a link at the bottom to the fla's to see for yourself. For one, (and i dont know how to adapt the code for this) when you login as say matt, the "matt box" should fall from its current y position to the specified, while all others (4 of them) fade out. they are all in a column though so i dont think thats going to work like that, as the current tween class is specifiying an y value to start from (in this case 48, which is the matt box y value, the ryan y value may be 130 and so forth...
                                                                      "var drop:Object = new mx.transitions.Tween(usrName, "_y", mx.transitions.easing.Bounce.easeOut, 48, 380, 2, true);"
                                                                      as well - give it a test run and see for yourself what goes on - i cant account for it, maybe you can shine some light?

                                                                      again kglad - i feel really bad for constantly asking you to save me, but i really am getting there (especially with that last bit of cleaned up code!) i have a tendency to make huge long overredundant scripts so this should help me collapse things a little!.

                                                                      Thanks again good Sir,

                                                                      link: http://mattgroth.echointernet.net/temp/Lists.zip

                                                                      --][--
                                                                      • 33. Re: refreshing without looping???
                                                                        ][odine Level 1
                                                                        i figured one of the issues was because the mymessage function was defined twice (dont laugh it took me a little while to see!) i was trying to generalize that function like you have the rest to take the usrName var and use it instead of wiritng it for each user. I am having problems with this line...

                                                                        new mx.transitions.Tween(usr_matt.logout, "_x", mx.transitions.easing.Bounce.easeOut, 25, 140, 3, true);

                                                                        it seems it only works if i reference it like that, if i cange it to ("usr_"+usrName.logout,) it doesnt work, no matter how i try to reference it, but it works for everything else! go figure :S

                                                                        As well - as i said i want everything but the "usr_"+usrName to fade out (right now its only one that does) now in my head im seeing (and from what ive seen you do) and array will be the way to do it? except somehow exlude usrName?

                                                                        --][--
                                                                        • 34. Re: refreshing without looping???
                                                                          kglad Adobe Community Professional & MVP
                                                                          oh, i ididn't check myMessage. here's a corrected version with myMessage being called. i'm not sure what your moviecliploader's are supposed to do so they're probably not going to work:

                                                                          • 35. Re: refreshing without looping???
                                                                            ][odine Level 1
                                                                            okay i cant figure it out - i have tried everything...

                                                                            new mx.transitions.Tween(tl["usr_"+usrName].logout
                                                                            does not work
                                                                            new mx.transitions.Tween(usr_matt.logout
                                                                            does work

                                                                            I did a trace right before its called and usrName = matt at this stage...then why on earth doesnt the first one work?!

                                                                            kglad - the movieclip loaders are what load the editlist.swf into the movie...at least that was the plan lol.
                                                                            • 36. Re: refreshing without looping???
                                                                              kglad Adobe Community Professional & MVP
                                                                              what's movieclips have a child logout?
                                                                              • 37. Re: refreshing without looping???
                                                                                ][odine Level 1
                                                                                all the usr_+usrName mc's have a mc in them. When the usr_+usrName movieclip transitions down via the tweenF function and it reaches the bottom, this logout movieclip should slide out as the tween suggests.
                                                                                • 38. Re: refreshing without looping???
                                                                                  kglad Adobe Community Professional & MVP
                                                                                  there's no logout child in the file i downloaded. did you add the child movieclip? if so, will it be visible after its parent is tweened?
                                                                                  • 39. Re: refreshing without looping???
                                                                                    ][odine Level 1
                                                                                    http://mattgroth.echointernet.net/works.zip

                                                                                    just publish the login to get the SWF then run the desktop.fla to see what i mean - login as matt - test to see how it should work. you will not i had to change the code to new mx.transitions.Tween(usr_matt.logout for it to work (which means if you try loggin in as anyone else it will be wrong. hope that helps. thanks again kglad.
                                                                                    1 2 Previous Next