Skip to main content
warpigs666
Inspiring
March 17, 2018
Answered

Possible to change frame based on object location?

  • March 17, 2018
  • 1 reply
  • 644 views

Hi. If I am moving an object, any sort of object (let's say a drawn layer) using the left and right arrow keys, is it possible to jump to a specified frame based on where that object is? So let's say that I am moving it one frame at a time, can I write some sort of javascript or anything to say "once the object is in this quadrant jump to frame xx"? I want it to be like a video game scenario where users and make the character walk through a door and then have everything jump to a new frame when the character has crossed that threshold.

    This topic has been closed for replies.
    Correct answer kglad

    Javascript, would be eternally grateful.


    document.onkeydown = keyF.bind(this);

    function keyF(e){

    switch(e.keyCode){

    case 37:

    //move left

    break

    case 38:

    // move up

    break

    case 39:

    // right

    break

    case 40:

    //down

    break

    }

    if(this.obj1.x<x1 && this.obj1.x>x2 && this.obj1.y<y1 && this.obj1.y>y2){

    this.gotoAndStop(wherever);

    }

    }

    1 reply

    kglad
    Community Expert
    Community Expert
    March 17, 2018

    are you asking about something the user does with your finished app (move an object using arrow keys) or something you do while creating your app?

    warpigs666
    Inspiring
    March 17, 2018

    Something the user does. As in they would be moving the character around with their arrow keys.

    kglad
    Community Expert
    Community Expert
    March 17, 2018

    use an if-statement (in your key listener) checking the object's position.

    p.s. your question is baffling because you're asking about the most basic actionscript (goto) and not asking about more complicated actionscript (moving an object with arrow keys).