Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Actionscript 3 simple jigsaw puzzle question

New Here ,
Jan 07, 2014 Jan 07, 2014

Hello, I am attempting to modify a tutorial on jigsaw puzzles to my own needs. I am very new to AS3

What I am trying to do is very simple (I believe), I have a 6 piece jigsaw puzzle and after every piece is placed in the correct spot I would like it to lock it down and play a wav file.

the code I am using for each piece is:

_________________________________________

stop();

import flash.events.Event;

import flash.events.MouseEvent;

stage.addEventListener(Event.ENTER_FRAME,EntFrame);

function EntFrame(e:Event):void

{

    //piece1

    Piece1_mc.addEventListener(MouseEvent.MOUSE_DOWN, DragP1);

    function DragP1(event:MouseEvent):void

    {

        Piece1_mc.startDrag();

    }

    stage.addEventListener(MouseEvent.MOUSE_UP, DropP1);

    function DropP1(event:MouseEvent):void

    {

        Piece1_mc.stopDrag();

    }

    if (Targ1_mc.hitTestObject(Piece1_mc.Tar1_mc))

    {

        Piece1_mc.x = 260.90;

        Piece1_mc.y = 432.80;

        gotoAndPlay(2)

        audio_mc.gotoAndPlay(2);

    }

}

___________________________________________________________

The issue seems to be that the audio file continues to play over and over since the Targ1_mc is constantly registering as hitting.


Locking the pieces is also an issue, I have tried to replace the Piece1_mc on the frame 2 with a still version of the puzzle piece but then I get a #1009 error and lose all code functionality, I am guessing this is due to my needing to removeEventListener but I am not sure how to go about that.

I hope this makes sense to someone, thank you in advance.

TOPICS
ActionScript
829
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 07, 2014 Jan 07, 2014
LATEST

You probably want to start by removing the surrounding EntFrame function and the listener that executes it.  You only need the drag and drop functions with their listeners for what you seem to be wanting to do.  The entFrame function is redoing it all at the frame rate of your file.  That conditional you have near the end wants to be checked inside the drop function, not outside it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines