Can't interact with tiles in an interactive jigsaw puzzle (Flash CC AS3)

95 views Asked by At

I am am doing this for a interactive assignment for a media arts class and I have no idea how to code in action script 3. I took the orignal code from a tutorial and it didn't work so I came here and attempted to learn how to modify it.

AS3 Code

//*********************
// Initialize:

flash.events.MouseEvent
var numPieces = 16;

for (var i = 0; i < numPieces; i++)
{
    var pieceName = "p" + (i + 1);
    var piece = this[pieceName];
    if( piece ){
        piece.name = pieceName;
        piece.addEventListener(MouseEvent.MOUSE_DOWN, function)(evt) 
        {
            this.scaleX = 1;
            this.scaleY = 1;
            this.shadow = null;
            this.parent.addChild(this);// Bump to top
            this.offset = {x:this.x - evt.stageX, y:this.y - evt.stageY};
        });
        piece.addEventListener(MouseEvent.MOUSE_MOVE, function) 
        {
            this.x = evt.stageX + this.offset.x;
            this.y = evt.stageY + this.offset.y;
        });
        piece.addEventListener(MouseEvent.MOUSE_UP, function)(evt) 
        {
            var target = this.parent["t"+this.name.substr(1)];
            if( target && hitTestInRange( target, 30) ){
                this.x = target.x;
                this.y = target.y;
            }
        });
    }
}

function hitTestInRange( target, range )
{
    if( target.x > stage.mouseX - range &&
        target.x < stage.mouseX + range &&
        target.y > stage.mouseY - range &&
        target.y < stage.mouseY + range )
    {
        return true;
    }
    return false;
}

Please help me fix this code so I can run my puzzle and move the pieces. I can upload the flash file if needed

0

There are 0 answers