dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: If you came from certain frame and pressed ENTER - go to other certain frame

  1. #1
    Junior Member
    Join Date
    May 2019
    Posts
    26

    If you came from certain frame and pressed ENTER - go to other certain frame

    Hi, is there some code (actionscript 2.0) for following function:

    onEnterFrame = function() {
    if(YOU CAME HERE FROM FRAME 1 && Key.isDown(Key.ENTER)){
    gotoAndPlay("certain frame");
    }
    if(YOU CAME HERE FROM FRAME 4 && Key.isDown(Key.ENTER)){
    gotoAndPlay("other certain frame");
    }
    }

  2. #2
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,797
    Just create a variable at the start and then:
    Code:
    var lastFrame=0;
    onEnterFrame = function() {
        if(Key.isDown(Key.ENTER)){
            switch(lastFrame){
                case 1:
                swapFrame("target frame");
                break;
            }
        }
    }
    function swapFrame(targetFrame:Int){
        lastFrame=_currentFrame;
        gotoAndPlay(targetFrame);
    }
    I added the function so that it updates the lastFrame when it's time to move to a new frame. Also, using the enter key as an input with multiple frames might create problems because it will start playing again.

    I've noticed that you don't use the stop() command. Did you miss it?
    .

  3. #3
    Junior Member
    Join Date
    May 2019
    Posts
    26
    hm...there is some mistake in line ''function swapFrame(targetFrame:Int){'' ... 'int' could not be loaded? In any case, I`m not sure where do I need to type that code. I have frame 1,2,3,4 and 5. In all frames is stop() command. By command 'onEnterFrame' frame 1 can go to 2 and to 3 (for example, by key.UP goes to 2 and by key.DOWN goes to 3). By key.RIGHT, frame 2 goes to 3. Code that I need should be for frame 3 (and also in frame 3?): if you came in frame 3 from frame 1 - press ENTER and go to frame 4, but if you came in frame 3 from frame 2 - press also ENTER but go to frame 5.
    https://we.tl/t-5Nzvpe5qmp is test2.fla file for example.

  4. #4
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,797
    I forgot int would be short for integer. as2 doesn't have that so you can either just delete it or replace it with Number. It won't matter too much.

    Ugh, I just found out that it's a bad idea to use a number for labels. Using them like you are is the only real way for it to work. Basically there's no way to create a generic function to gotoAndPlay to a label that's a number.

    Test2.fla Here, this does what you want. I ended up adding a letter to the label name to get it to work. You can avoid that by just using the oldFrame variable and modify it manually yourself if you'd prefer the old way.
    .

  5. #5
    Junior Member
    Join Date
    May 2019
    Posts
    26
    Oh, it works nice. Maybe that letter confuses a little bit, but this is not a problem, I can move it from viewscreen. Thanks.

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