Iffy on IF Statements

Ahoy hoy.

What I have now

What I have are 9 buttons for my portfolio section of my site, what I had happening is that you click the button, and the button moves right, expands its height and width, and moves to the appropriate Y position, so you now have a much larger box that will display my portfolio content (note: this won’t happen any more because of modifications made trying to get the below working, but if you comment off the IF statements where they command the box to move, you will see it partially).

What I want to do

I want to make the whole opening process sequential. As in, have the button move right after its clicked, and then become wider (and then have a loader go across as well), after thats complete, have it move to the appropriate Y position and finally drop down to the correct height.

I’ve been annoying Timmee on MSN Messanger about it, and we can’t seem to get it to work. I started rewriting the code I had earlier today to make it more managable, and hoped that would also make it work. Heres the code I started writing today, based off the code I had been struggling with for the last few days:


function moveBox(mc, dir, easeType, begin, end, time) {
	//function to have the box move to certain places
	boxTween = new mx.transitions.Tween(mc, dir, easeType, begin, end, time);
}
//function to actually move the boxes
function openBox(target, x1, x2, y1, y2, w1, w2, h1, h2) {
	//function to query whether the box had fully moved over to the right first, before expanding
	function checkPos() {
		trace(target._x);
		//This is where the problem is:
		//outputs the position of the button pressed (final number = 50, same as x2)
		trace(x2);
		//outputs 50
		if (target._x == x2) {
			_global.xDone = true;
		}
		if (target._width == w2) {
			_global.wDone = true;
		}
		if (target._y == y2) {
			_global.yDone = true;
		}
	}
	//interval the checkPos function, so it can see when the box is fully moved over, no idea why it doesn't work
	cpInterval = setInterval(checkPos, 10);
	//move the box right
	moveBox(target, "_x", mx.transitions.easing.Bounce.easeOut, x1, x2, 30);
	if (xDone) {
		moveBox(target, "_width", mx.transitions.easing.Bounce.easeOut, w1, w2, 30);
	}
	if (wDone) {
		moveBox(target, "_y", mx.transitions.easing.Bounce.easeOut, y1, y2, 30);
	}
	if (yDone) {
		moveBox(target, "_height", mx.transitions.easing.Bounce.easeOut, h1, h2, 30);
	}
}
MovieClip.prototype.box = function() {
	this.onRelease = function() {
		openBox(this, this._x, 50, this._x, 10, 15, 500, 15, 175);
		//openBox(target, x1, x2, y1, y2, w1, w2, h1, h2)
	};
};
box1.box();
//this will be expanded to suit 9 buttons, I just started rewriting the code

That code is very rough around the edges and will need to be expanded further to support the 9 boxes I have, but Timmee suggested getting one working sequentially first before rewriting all the code in a different just to get the same, frustrating result.

Is there any way I can rewrite that checkPos function and interval to actually work? It probably, and hopefully is something very simple. If you’d like, I’ll throw the FLA and SWF onto my server to download and fiddle.

Thanks all.


Update, someobody at AS[org] suggested that I put an onEnterFrame function around the IF statements, didn’t work. Heres a link to the AS[org] thread.

I think that your basic problem is in the namespace. When CheckPos is being called by SetInterval, it is no longer within openBox so target no longer exists. Your should have SetInterval pass target to CheckPos. Also it looks to me like there will be some other changes needed for CheckPos to actually do something if it detects the correct position because right now you’re only checking the state of the _global vars once, right after you call MoveBox. All the code in the if(xdone) etc statements should be moved into CheckPos. Hope this helps.

I love you! :love:

Moved the IF statements into the checkPos function, added a wGone variable to it *because everytime the function whipped around, it would start the width over again. Heres the code:

function openBox(target, x1, x2, y1, y2, w1, w2, h1, h2) {
	function checkPos() {
		if (target._x == x2 && !wStart) {
			moveBox(target, "_width", mx.transitions.easing.Bounce.easeOut, w1, w2, 30);
			wStart = true;
		}
		if (target._width == w2) {
			moveBox(target, "_y", mx.transitions.easing.Bounce.easeOut, y1, y2, 30);
		}
		if (target._y == y2) {
			moveBox(target, "_height", mx.transitions.easing.Bounce.easeOut, h1, h2, 30);
		}
	}
	cpInterval = setInterval(checkPos, 10);
	moveBox(target, "_x", mx.transitions.easing.Bounce.easeOut, x1, x2, 30);
}
//still need to add the other "_Start" variables to the IF statement

Thanks so much again :slight_smile: