Image

Imagepinkdagger wrote in Imageflashdev 😡frustrated

More "if" code help :(

Me again! Sorry I've been back so much, but this recent task seems difficult. A friend and I even asked the professor and she had no idea how to do it - yet expected us to miraculously figure it out. We were taught "swap" code after this was assigned, so I'm not sure if it (would work) is required, but I'm familiar with "if" statements.

Problem: When the "gargoyle" is clicked by the target/mouse, it changes into a heart. When clicked again, it should change back into a gargoyle. Lather, rinse, repeat.

What I've tried: "If" statements without changing the variable names, changing the variable names, some completely randomized trial and error that did nothing good.

I'm working with ActionScript 2, Flash CS3 Professional if that makes a difference.


The code:
var garg1:MovieClip = attachMovie("gargoyle","garg1",1) ;
garg1._x = 300 ;
garg1._y = 300 ;
garg1._xscale = 20 ;
garg1._yscale = 20 ;
garg1._xscale *= -1 ;

var garg2:MovieClip = attachMovie("gargoyle","garg2",2) ;
garg2._x = 100 ;
garg2._y = 300 ;
garg2._xscale = 20 ;
garg2._yscale = 20 ;
garg2._xscale *= -1 ;


var heart:MovieClip = attachMovie("scopeTarget","h4",4) ;
heart._x = _xmouse ;
heart._y = _ymouse ;
heart._xscale = 20 ;
heart._yscale = 20 ;

Mouse.hide() ;



var g1xv:Number = 5 ;
var g1yv:Number = 5 ;
var g2xv:Number = 5 ;
var g2yv:Number = 3 ;


mouseHandler = new Object() ;
mouseHandler.onMouseDown = function() {


if ( garg1.hitTest( _xmouse, _ymouse) ) {

var tempX:Number = garg1._x ;
var tempY:Number = garg1._y ;
var tempWidth:Number = garg1._width ;
var tempHeight:Number = garg1._height ;
garg1.removeMovieClip() ;
garg1 = attachMovie("heart","garg1",1) ;
garg1._x = tempX ;
garg1._y = tempY ;
garg1._width = tempWidth ;
garg1._height = tempHeight ;
g1xv *= -5 ;
g1yv *= -5 ;


}

if ( garg1.hitTest( _xmouse, _ymouse) ) {

var tempX:Number = garg1._x ;
var tempY:Number = garg1._y ;
var tempWidth:Number = garg1._width ;
var tempHeight:Number = garg1._height ;
garg1.removeMovieClip() ;
garg1 = attachMovie("gargoyle","garg1",1) ;
garg1._x = tempX ;
garg1._y = tempY ;
garg1._width = tempWidth ;
garg1._height = tempHeight ;
g1xv *= 1 ;
g1yv *= 1 ;



}


if ( garg2.hitTest( _xmouse, _ymouse) ) {

garg2.removeMovieClip() ;
garg2 = attachMovie("heart","garg2",2) ;
g2xv *= -5 ;
g2yv *= -5 ;

}

if ( garg2.hitTest( _xmouse, _ymouse) ) {

garg2.removeMovieClip() ;
garg2 = attachMovie("gargoyle","garg2",2) ;
g2xv *= 1 ;
g2yx *= 1 ;


}

}

Mouse.addListener(mouseHandler) ;


onEnterFrame = function () {


garg1._x += g1xv ;
garg1._y += g1yv ;
garg2._x += g2xv ;
garg2._y += g2yv ;


heart._x = _xmouse ;
heart._y = _ymouse ;



if ( (garg1._x + (garg1._width/2) ) >= Stage.width) {
garg1._x = Stage.width - (garg1.width / 2) ;
g1xv *= -1 ;
garg1._xscale *= -1 ;
}


if ( (garg1._x - (garg1._width/2)) <= 0 ) {
garg1._x = garg1._width / 2 ;
g1xv *= -1 ;
garg1._xscale *= -1 ;
}


if ( (garg1._y + (garg1._height/2)) >= Stage.height) {
garg1._y = Stage.height - (garg1._height / 2) ;
g1yv *= -1 ;
}


if ( (garg1._y - (garg1._height/2) ) <= 0) {
garg1._y = garg1._height / 2 + 1 ;
g1yv *= -1 ;
}




if ( (garg2._x + (garg2._width/2) ) >= Stage.width) {
garg2._x = Stage.width - (garg2._width / 2) ;
g2xv *= -1 ;
garg2._xscale *= -1 ;
}


if ( (garg2._x - (garg2._width/2)) <= 0 ) {
garg2._x = garg2._width / 2 ;
g2xv *= -1 ;
garg2._xscale *= -1 ;
}


if ( (garg2._y + (garg2._height/2)) >= Stage.height) {
garg2._y = Stage.height - (garg2._height / 2) ;
g2yv *= -1 ;
}


if ( (garg2._y - (garg2._height/2) ) <= 0) {
garg2._y = garg2._height / 2 ;
g2yv *= -1 ;
}





}


Any help is insanely appreciated. You guys are godsends.