PDA

View Full Version : if/else conditional statement problems


Okay
10-23-2005, 09:12 PM
Hi, I've been racking my head trying to figure out why the conditionals in the "checkSelectionLoc" function aren't enabling / disenabling the buttons when they are supposed to. The AS is attached to the thumbnail scroller in the portfolio section of this site:
http://danielstromborg.com/temp/dahan/dahan_index.html

function activateTnailbuttons(){
var STEP:Number = 61;//sets the incremental number

mc_downArrow.button.onRelease = function() {
mc_downArrow.button.enabled=false;
var clip:MovieClip = mc_tnailSelection;//declares the variable "clip". "clip" is a MovieClip called "mc_tnailSelection"
checkSelectionLoc(clip._y-STEP);//checks the location of the mc "mc_tnailSelection"
mc_tnailSelection.slideTo(clip._x,clip._y-STEP, 0.7,"easeOutExpo",0,renableDownButton);// uses Laco's .slideTo scripts--"clip" is unchanged in X, and takes "clips" current Y value and subtracts 61 (as declared in the var STEP) over a period of .7 seconds
};

mc_upArrow.button.onRelease = function() {
mc_upArrow.button.enabled=false;
var clip:MovieClip = mc_tnailSelection;//declares the variable "clip". "clip" is a MovieClip called "mc_tnailSelection"
checkSelectionLoc(clip._y+STEP);//checks the location of the mc "mc_tnailSelection"
mc_tnailSelection.slideTo(clip._x,clip._y+STEP, 0.7,"easeOutExpo",0,renableUpButton);// uses Laco's .slideTo scripts--"clip" is unchanged in X, and takes it's current Y value and adds 61 (as declared in the var STEP) over a period of .7 seconds
};
};



function checkSelectionLoc(endPoint:Number){
//check Y value of thumbnail clip / "mc_tnailSelection"
if (endPoint >= 578){//if the endpoint is greater than 578
mc_upArrow.button.enabled = false;//toggle button off
trace("endpoint = 578");
} else {//otherwise do this
mc_upArrow.button.enabled = true;//turn button on
trace("endpoint != 578");
}

//check Y value of thumbnail clip / "mc_tnailSelection"
if (endPoint <= 334){
mc_downArrow.button.enabled = false;
trace("endpoint = 334");
} else {
mc_downArrow.button.enabled = true;
trace("endpoint != 334");
}
};

function renableUpButton(){
mc_upArrow.button.enabled=true;
};

function renableDownButton(){
mc_downArrow.button.enabled=true;
};


The downward button disabling code seems to work ONLY after you have scrolled down further than the _y=334 (where I thought this code should disable the button), and then back up. Once it goes back up to the _y=334, the code seems to work. ... but that's not what I want. When it hits 334 for the first time, I want the code to disable the button so it doesnt go any further down.

Make sense? Just looking for a little explaination on what I am doing wrong here.

Thanks for reading.

silentweed
10-23-2005, 09:33 PM
your logic seems to be kind of wrong..for e.g lets suppose y= 600..

Then when this code is encountered

if (endPoint >= 578){//if the endpoint is greater than 578
mc_upArrow.button.enabled = false;//toggle button off
trace("endpoint = 578");
} else {//otherwise do this
mc_upArrow.button.enabled = true;//turn button on
trace("endpoint != 578");
}


the button is disabled. But then the following code is encountered and the else statement is executed which enables the button


if (endPoint <= 334){
mc_downArrow.button.enabled = false;
trace("endpoint = 334");
} else {
mc_downArrow.button.enabled = true;
trace("endpoint != 334");
}
};



see what i mean?

Okay
10-23-2005, 09:49 PM
well my hope is that it never gets to 600. Do you have a suggestion on how to rethink this? Admitingly, logic never was my strong point.