Welcome, Guest
  • Author Topic: looping frame breaks mouse event  (Read 1324 times)

    mrsnoogle

    • Server what's that
    • *
    • Posts: 1
      • View Profile
      • Email
    looping frame breaks mouse event
    « on: 04/28/11, 13:51 »
    G'day. I am quite new to action script and have run into a bit of trouble and was hoping someone was kind enough to point me in the direction I should be going.

    I have a picture of a van moving on its x and y in relation to the mouse movement on screen..

    stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMovement);

    function mouseMovement(e:MouseEvent):void{
       
       van.x = (mouseX/20) + 490;
       van.y = (mouseY/20) + 285;
    }

      .... And this is working fine but the moment I add anything after frame 1 things stop working. I want to loop on frame 1 until the user clicks a buttons and then jump to say frame 100 where the frame loops again until the user clicks another button and jumps to a new looped frame again. I have tired

    addEventListener(Event.EXIT_FRAME,cycle);
    function cycle(event:Event) {
       gotoAndPlay(1);
    }

    but this breaks the van moving on its x and y and the van jumps around weirdly when i move the mouse around. Any help I could get here would be really appriciated!
                                                                                                                                   ... Camm

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: looping frame breaks mouse event
    « Reply #1 on: 04/28/11, 15:05 »
    Cut your application into separate clips.

    The main clip does not need to have graphical content, or maybe a background.

    This clip contains all the code and only one frame.

    Now you can load, or include as many clips you like.

    Clips, containing scripts, especialy funktions etc. should not move frames.
    If you leave the frame, where the funktion is defined, you are losing the reference.
    If you return to this frame, you wil reinitialize all object beeing defined there.
    This is usualy not the behaviour, you want to have.
    happy flashing
    8)
    Ronald