A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: Movie clip move to frame

  1. #1
    Senior Member
    Join Date
    Apr 2004
    Posts
    132

    Movie clip move to frame

    I have a movie clip where actionscript takes place to check a user input.

    The crux of what I'm trying to achieve is to check user input against 3 codes....

    dave, koit & penguins.

    If the user enters any code, then the playhead of the mc should go to flag "open" - and yet, it doesn't. It moves to the next frame which is in this instance "locked".

    It should move to "locked" if the if statement returns a code other than those 3 above.

    This is basic stuff and yet it doesn't want to play ball.

    Can someone please look at the attached code and see if they can find it as I've been wracking my brain all day and yesterday.
    Attached Files Attached Files

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Remove 'this' keyword from this.gotoAndPlay("open");
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  3. #3
    Senior Member
    Join Date
    Apr 2004
    Posts
    132
    Tried that, still won't work - removed all instances of this. but all that happens is that no matter what I press, locked gets played and then we go to open. The playhead just doesn't want to move where it is supposed to.

    Any other suggestions !?

  4. #4
    Senior Member
    Join Date
    Apr 2004
    Posts
    132
    Any suggestions ?

  5. #5
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Dude, I founds a couple problems. The textfield names are changing, but if statements are referencing old variables. Some variables are not being populated BEFORE being placed in conditional.

    Don't let the timeline control the variables...have the code to it.... I had started to make corrections....first have a single actionscript keyframe, and not multiple. Reuse many of the objects already on the stage. Using a switch statement instead of an if statement. Using the method you have now (timeline control) the user is forced to wait until the frame head reaches the appropriate frame and provides the correct response....

    Step back a little and map out what you need and reorganize your project.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  6. #6
    Senior Member
    Join Date
    Apr 2004
    Posts
    132
    Still having trouble with this.......

    On frame 2 of this movie clip you can see that I have a key listener.

    When the enter/return keys are pressed, whatever is in the input text box (Code, with variable name Codey) is validated. Or should be. If the input is say "dave", then a variable should be set and then the playhead should move to the frame label "open".

    I've tried this.gotoAndPlay("open") and gotoAndPlay("open")

    All the anim will do is take you to frame "locked" which should only happen if anything other than say "dave" is entered.

    Why will the playhead not go to ("open") !?!?!


    Stepping back and reassessing have not helped me find this little bug !!

    Any help would be very much appreciated.

    Koit
    Attached Files Attached Files

  7. #7
    Senior Member
    Join Date
    Apr 2004
    Posts
    132
    Please, some kind soul !?

  8. #8
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    I don't even know where to start.
    1. frame 2: your "if" statements will run as soon as you enter this frame. They won't run again unless we leave the frame and then come back. so they are really doing nothing.

    I entered dave and it said "open" I entered koit and it said "open" penguin did not work. You need to use trace() statements so that you can see what is going on behind the scenes.

    It appears there is a lot going on. I would try to just focus on one part and getting that working, then move on to the next. I would dig a little more, but I am at work and can not have this on my screen.

    IMS

  9. #9
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    here is the first problem:
    frame 2:

    PHP Code:
    this.onEnterFrame = function() {
        
    keyWatch.onKeyDown = function(){
            
            if(
    Key.getCode() == 13 || Key.getCode() == 112){
                
    trace('Codey: 'Codey);
                if (
    Codey == "dave" || Codey == "DAVE"){
                    
    _root.twelvecode 1;
                    
    gotoAndPlay("open");
                }
                else if (
    Codey == "koit" || Codey == "KOIT"){
                    
    _root.koitcode 1;
                    
    gotoAndPlay("open");
                }            
                else if (
    Codey == "penguins" || Codey == "PENGUINS"){
                    
    _root.penguinscode 1;
                    
    gotoAndPlay("open");
                }            
                else {
                    
    Selection.setFocus("Code");
                    
    Code.text "";
                    
    gotoAndPlay("locked");
                            }
            }
        }

    You want to use if/else if statements. You just had if. Basically, when the code is run, first it checks to see if it is dave. If the answer is indeed dave, it still checks the other 2 if statements. the second if statement is false, it does not equal koit, and the third statement is false, it does not equal penguins, but the last if has an else statement, which says: if codey does not equal penguins, then go to and play"locked" which it does, and then goes to "open". by using if else if, once a statement is true, the statement is stopped.

    Hope that make sense

    IMS

  10. #10
    Senior Member
    Join Date
    Apr 2004
    Posts
    132
    You are a living breathing superstar.

    That makes sense and I thank you immensely for your time taken and your response.

    Thanks very much !!!

    Have a great evening.

  11. #11
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    second item:

    frame 2:
    your listener sends your playhead to the "open" frame, which will play to the code under the "openmenu" label. once you are at this code, your "if" statements will run, most tell the play head to go to and play "openmenu" which we are already at. so the play head then will proceed to frame 55 which then tells the play head to go to and play label "openmenu" so you are then stuck in a loop of the playhead going from label "openmenu" and frame 55. At this point if you enter any text, the last else statement will run sending you to the "openerror" label which sends us back the the "openmenu" label. If you now enter "dave" the playhead will go to label "alreadytwelve" which then proceeds to frame 55 which sends us back to openmenu. Have you ever used functions before?

    You have a good start, it's just hard to figure out what exactly is going on when you start to add frames and labels. Like Samac said, step back, and maybe draw this out on paper what it is you want to do, then start building. Also build in small chanks and test frequently. If you try to code too much too fast it can get very hard to troubleshoot.

    IMS

  12. #12
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    Final lesson for the day:

    put this code in frame 2, looks like yours except for a couple of trace()'s and if/else if, also put the if/else if in a function.

    PHP Code:
    //check which buttons should be on screen
    //all buttons
    function fnCheckCode(){
        
    trace('twelve code: '_root.twelvecode' koit code: '+_root.koitcode' penguin code: '+_root.penguinscode);
        if (
    _root.twelvecode == && _root.koitcode == && _root.penguinscode == 1) {
            
    Code.text "";
            
    bonusbutton.enabled true;
            
    bonusbutton._visible true;
            
    bonus2.enabled true;
            
    bonus2._visible true;
            
    bonus3.enabled true;
            
    bonus3._visible true;
            
    gotoAndPlay("allcodes");
        }
        
    //bonus & koit only 
        
    else if (_root.twelvecode == && _root.koitcode == && _root.penguinscode != 1) {
            
    Code.text "";
            
    bonusbutton.enabled true;
            
    bonusbutton._visible true;
            
    bonus2.enabled true;
            
    bonus2._visible true;
            
    bonus3.enabled false;
            
    bonus3._visible false;
            
    already._visible false;
            
    twelvey._visible false;
            
    another._visible true;
            
    notvalid._visible false;
            
    gotoAndPlay("openmenu");
        }
        
    //bonus & penguins only 
        
    else if (_root.twelvecode == && _root.koitcode != && _root.penguinscode == 1) {
            
    Code.text "";
            
    bonusbutton.enabled true;
            
    bonusbutton._visible true;
            
    bonus2.enabled false;
            
    bonus2._visible false;
            
    bonus3.enabled true;
            
    bonus3._visible true;
            
    already._visible false;
            
    twelvey._visible false;
            
    another._visible true;
            
    notvalid._visible false;
            
    gotoAndPlay("openmenu");
        }
        
    //koit & penguins only 
        
    else if (_root.twelvecode != && _root.koitcode == && _root.penguinscode == 1) {
            
    Code.text "";
            
    bonusbutton.enabled false;
            
    bonusbutton._visible false;
            
    bonus2.enabled true;
            
    bonus2._visible true;
            
    bonus3.enabled true;
            
    bonus3._visible true;
            
    already._visible false;
            
    twelvey._visible true;
            
    another._visible false;
            
    notvalid._visible false;
            
    gotoAndPlay("openmenu");
        }
        
    //penguins only 
        
    else if (_root.twelvecode != && _root.koitcode != && _root.penguinscode == 1) {
            
    Code.text "";
            
    bonusbutton.enabled false;
            
    bonusbutton._visible false;
            
    bonus2.enabled false;
            
    bonus2._visible false;
            
    bonus3.enabled true;
            
    bonus3._visible true;
            
    already._visible false;
            
    twelvey._visible true;
            
    another._visible false;
            
    notvalid._visible false;
            
    gotoAndPlay("openmenu");
        }
        
    //koit only 
        
    else if (_root.twelvecode != && _root.koitcode == && _root.penguinscode != 1) {
            
    Code.text "";
            
    bonusbutton.enabled false;
            
    bonusbutton._visible false;
            
    bonus2.enabled true;
            
    bonus2._visible true;
            
    bonus3.enabled false;
            
    bonus3._visible false;
            
    already._visible false;
            
    twelvey._visible true;
            
    another._visible false;
            
    notvalid._visible false;
            
    gotoAndPlay("openmenu");
        }
        
    //bonus only 
        
    else if (_root.twelvecode == && _root.koitcode != && _root.penguinscode != 1) {
            
    Code.text "";
            
    bonusbutton.enabled true;
            
    bonusbutton._visible true;
            
    bonus2.enabled false;
            
    bonus2._visible false;
            
    bonus3.enabled false;
            
    bonus3._visible false;
            
    already._visible false;
            
    twelvey._visible true;
            
    another._visible false;
            
    notvalid._visible false;
            
    gotoAndPlay("openmenu");
        }
    }

    this.onEnterFrame = function() {
        
    keyWatch.onKeyDown = function() {

            if (
    Key.getCode() == 13 || Key.getCode() == 112) {
                
    trace('Codey: '+Codey);
                if (
    Codey == "dave" || Codey == "DAVE") {
                    
    _root.twelvecode 1;
                    
    gotoAndPlay("open");
                } else if (
    Codey == "koit" || Codey == "KOIT") {
                    
    _root.koitcode 1;
                    
    gotoAndPlay("open");
                } else if (
    Codey == "penguins" || Codey == "PENGUINS") {
                    
    _root.penguinscode 1;
                    
    gotoAndPlay("open");
                } else {
                    
    Selection.setFocus("Code");
                    
    Code.text "";
                    
    gotoAndPlay("locked");
                }
                
    fnCheckCode();
            }
        }
    }

    stop(); 
    Also, you can get rid of this code in the other frames, you only need it in frame 2.

    Give it a try, it should do what you want, might have to tweak it a bit.

    good luck

    IMS

  13. #13
    Senior Member
    Join Date
    Apr 2004
    Posts
    132
    Tried that, and unfortunately, no joy. Now as soon as I press enter, nothing happens at all. See my updated flash version..........

    This is really odd.

    My plan is this, this little piece of a much larger animation is just a way of getting a user to enter "bonus codes" to unlock extra scenes. What it should do :-

    Upon entry into the first frame, it should check to see which codes have already been entered (note there is a back button so people can come and go as they please - but I don't want them to have to enter the same codes again) and display the appropriate buttons and message.

    If they do not have the main bonus code (in this case, "dave") then it should always ask for the 12 digit code......(that sounds weird I know but the actual bonus code will be 12 digits long when I've finalised everything.......

    If a code has already been entered, I want the message to display "already entered"

    If a code is invalid, I want the message to display "invalid"

    On paper this is so simple, in my mind it's easy, yet I cannot translate it effectively to code.


    Your help has been invaluable but if you can assist a little further I'd be ever so grateful.
    Attached Files Attached Files

  14. #14
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    looks like on frame one, you accidentally removed your listener:

    PHP Code:
    Selection.setFocus("Code");

    keyWatch = new Object();
    Key.addListener(keyWatch); 
    Frame one should have this code:

    PHP Code:
    Selection.setFocus("Code");

    keyWatch = new Object();
    Key.addListener(keyWatch);


    //initial buttons made invisible & variables set
    bonusbutton.enabled false;
    bonusbutton._visible false;
    bonus2.enabled false;
    bonus2._visible false;
    bonus3.enabled false;
    bonus3._visible false;

    //initial text phrases set
    already._visible false;
    twelvey._visible true;
    another._visible false;
    notvalid._visible false
    Try that
    IMS

  15. #15
    Senior Member
    Join Date
    Apr 2004
    Posts
    132
    I need to ask you 1 more thing if I may......

    That did work, to a degree.


    1) The code works and does not allow errors that would lead to the code breaking. However, I also want an inbuilt checker that checks if a code has already been entered and then displays the appropriate message. As it stands, the incorrect code just gets deleted and we start again...... can that be done relatively easily ?

    Is that something that can be rectified ?
    Last edited by koit; 05-20-2009 at 01:54 PM. Reason: Asking more info...

  16. #16
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    There is a better way, but I figured this would make it a little easier to understand

    update:

    PHP Code:
    var sDaveEntered false;
    var 
    sKoit             false;
    var 
    sPenguins       false;


    this.onEnterFrame = function() { 
        
    keyWatch.onKeyDown = function() { 

            if (
    Key.getCode() == 13 || Key.getCode() == 112) { 
                
    trace('Codey: '+Codey); 
                if (
    Codey == "dave" || Codey == "DAVE") {
                    if(
    sDaveEntered == true){
                        
    //already entered dave
                    
    }else{
                         
    sDaveEntered true;
                        
    _root.twelvecode 1
                        
    gotoAndPlay("open");
                    }
                } else if (
    Codey == "koit" || Codey == "KOIT") {
                    if(
    sKoit == true){
                        
    //already entered koit
                    
    }else{
                        
    sKoit true;
                        
    _root.koitcode 1
                        
    gotoAndPlay("open");
                    }
                } else if (
    Codey == "penguins" || Codey == "PENGUINS") {
                    if(
    sPenguins == true){
                        
    //already entered penguins
                    
    }else{
                         
    sPenguins true;
                        
    _root.penguinscode 1
                        
    gotoAndPlay("open");
                    }
                } else { 
                    
    Selection.setFocus("Code"); 
                    
    Code.text ""
                    
    gotoAndPlay("locked"); 
                } 
                
    fnCheckCode(); 
            } 
        } 

    basically, we set 3 variables, then if they type one of the words, we set the variable to true, if they type it again, we will first check the variable, if it is true we will tell them already entered, if false, we continue and then set variable to true. Make sense?

    IMS

  17. #17
    Senior Member
    Join Date
    Apr 2004
    Posts
    132
    Thank you for your time.

    I'm all done now - visit www.highasakoit.co.uk soon and my penguins animation will be finished.

    My hosting is down at the moment, but will be up in a few days.

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