PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Multiple Passwords, Multiple Destinations
A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Multiple Passwords, Multiple Destinations

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    8

    Multiple Passwords, Multiple Destinations

    Hello!

    I'm doing an assignment for school and I basically have 0 knowledge of actionscript. I just copy/paste because I've never had the time to learn it.

    So basically what I need to do is create a field (password) that based on the password / value the user enter, they go to a certain frame.

    I want to have about 30 passwords, and 30 seperate frames for each one to go to.

    Can somebody help me out here?
    Thanks!

    p.s.

    Password: john -> gotoandstop (5)
    Password: bill -> gotoandstop (6)

    etc

    Thanks x2!

  2. #2
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Easy enough.

    You're going to want to have an array to store all the values. I'm assuming you have all the usernames/passwords already set. This is what you're going to do.

    Click on the first frame of the timeline. We're going to setup the stage. Drag a text box onto the stage, and open the properties panel (Ctrl F3?). Set it's type to an input box, and give it an instance name of inputUser.

    Do the same, drag another text box onto the stage, make it an input textbox and give it the instance name of inputPass. These are the two boxes we'll be using to setup the login.

    Now, drag a box onto the stage. Select the box and convert it into a symbol (F8), a button type. Give this an instance name of loginButton

    The stage is setup, let's code!



    Click on the first frame again and open the actions panel (F9) and put in the following code:

    PHP Code:
    stop();

    userNames = new Array ("Matt","John","Cathy")  // Continue to whatever number you want
    passWords = new Array ("123""doggie""flashkit"


    loginButton.onRelease = function(){
       
    getUser _root.inputUser.text;
       
    getPass _root.inputPass.text;

       for (
    i=0;i<userNames.length;i++){
           if (
    getUser == userNames[i] and getPass == passWords[i]){
                  
    _root.gotoAndStop (2);
           }
       }


    That is all there is to it. The only thing to note is the gotoAndStop (i + 2). The way this is set up is that each frame that you want the login to go to (you mentioned it was a unique frame for each login), will go to the usernames slot number of the array. The +2 is because the timeline starts on frame 1, and arrays start at 0.

    So for example, if I typed Matt and 123: since that login in the array is the first one, it's at 0. So, 0+2 = frame 2, which is the next one after the login screen. And so on and so forth.



    That's all there is to it!

  3. #3
    Junior Member
    Join Date
    May 2010
    Posts
    8
    Hey!
    Thanks so much, you're my idol.
    I havent tried this yet, but I'm sure it will work.
    I've been trying to learn AS all day and I've actually made a lot of progress.
    This doesn't look as foreign to me as when It would have when I first posted.

    Thanks bro, i'll let you know how i make out!
    Cheers.

  4. #4
    Junior Member
    Join Date
    May 2010
    Posts
    8
    Sorry for the double post, but can I get you to explain some of the elements of that?

    ie.

    " getUser = _root.inputUser.text;
    getPass = _root.inputPass.text;"

    what is the purpose of that?

    and

    for (i=0;i<userNames.length;i++){
    if (getUser == userNames[i] and getPass == passWords[i]){
    _root.gotoAndStop (i + 2);
    }
    }

    can you explain what each thing is doing here?

  5. #5
    Junior Member
    Join Date
    May 2010
    Posts
    8
    Triple Post!
    Didn't work bro.
    And I'm not retarded, I did it all correctly
    ..i click on my loginButton and she doesnt even change frames.
    any ideas?

  6. #6
    Junior Member
    Join Date
    May 2010
    Posts
    8
    QUAD POST!

    got it working!

    thanks man, but can u still explain stuff like:

    getUser = _root.inputUser.text;
    getPass = _root.inputPass.text;

    and

    if (getUser == userNames[i] and getPass == passWords[i]){


    and


    for (i=0;i<userNames.length;i++){

    and

    what _root means?

    THANK YOU!!!!!!!!!

  7. #7
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Glad you got it working.

    PHP Code:
    getUser _root.inputUser.text;
    getPass _root.inputPass.text
    Technically we don't need this, but I believe it's good practice to store information coming from a textbox into variables. Easier to manipulate and makes the syntax a little shorter. All this is doing is simply taking what the user types as their username and stores it in getUser, and also stores the password they type into getPass



    The FOR loop statement simply loops through the code between it to the number of usernames you have. So if you have 30 usernames stored in the array userName (where you typed them out), then it will loop through the code 30 times.

    What happens in between this loop?



    PHP Code:
    if (getUser == userNames[i] and getPass == passWords[i]){ 
    This is what is looped 30 times. It's basically an IF statement, which is a simple check to see if any type of condition is met. In our case, we're checking two things.

    First we're seeing if getUser (that is the variable storing the username they typed) matches any of the names in the array userName. We are also checking if the password they typed and is stored in getPass matches the corresponding password in our passWords array.

    If those two conditions are met, then you run the gotoAndStop(); code.



    For someone who has never looked at AS, it might be a bit much to grasp ... but seeing as it's for a project, you're probably just focused on finishing it rather than learning it. But maybe it'll interest you in the future.

    Good luck!

  8. #8
    Junior Member
    Join Date
    May 2010
    Posts
    8
    Thanks man! I have 2 more questions then you'll never see me again!
    1. I'm trying to make this happen on the stage of frame 24.

    Do I change " i=0 " to " i=23 "
    I've tried a few things, and when I input my information, the movie control does not switch frames. Any ideas?

    2. Also what is the [i] for?

    You've been great, sorry for all of this.
    Cheers

  9. #9
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Sorry I'm confused. Are you saying you want the successful logins to start from frame 24 and ending on frame 64 (30 pages/users)?

    If that's the case, change and replace with: _root.gotoAndStop (i + 24);.


    So for what [i] is ... basically, an array is a variable that stores multiple values, hence why we used it to store the userNames and another array to store the passWords. Since an array can store multiple values, we have to be able to retrieve any of these values at any given point.

    Each of the slots in an array are called the elements. So you had an array with 30 elements (as we do for the userNames), you can find out which element is storing what username by tracing: userNames[i].

    [i] represents any number ... so for example, userNames[2] might return the name "Cathy". Note that the first element in an array is element [0], so an array with 30 names contains elements 0-29.


    The reason why we use i, is because in the for loop, the i variable represents the number that is being looped 0 - 29 (or the length of the userName array). That way, it'll check every element in the array to see if there's a match.

    So that's why the IF statement says: if (getUser == userName [ i] ..., because it is essentially saying:

    • if (getUser == userName[0] and getPass == passWords[0])
    • if (getUser == userName[1] and getPass == passWords[1])
    • if (getUser == userName[2] and getPass == passWords[2])
    • if (getUser == userName[3] and getPass == passWords[3])
    • all the way through all the names



    If it DOES find a match, it tells the timeline to jump to a frame that is (now) starting at frame 24 plus whatever number [i] was. So, if the match was found on element 5 of the arrays, then it'll jump to frame 29 (24+5).

    Again, this is more advanced concepts that might take a little bit to grasp for a new comer. Good luck.

  10. #10
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    _root is the most first/main timeline. If you are inside a MovieClip or a Button, that's a new timeline in there, and if you have some code inside it you must call the code with the instance name of the button or the movieclip: E.G. I have a button with instances name Btn1, and a movieclip with instances name BtnHolder, so if i want to click that button from outside, i have to write on the "root" timeline
    Actionscript Code:
    BtnHolder.Btn1.onPress = function(){

    But if the button is out of the movieclip, on the main timeline, and the code is inside a movieclip, or on the timeline of a movieclip, we use:
    Actionscript Code:
    _root.Btn1.onPress = function();

    _root = main timeline

    And you can use the _root for any function, variable, action. Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center