Combining hitTest, drag and onEnter events

i’ve got a movie where i’ve got 3 color slider and 1 gray slider
the functionality is supposed to be that the gray slider moves along as the avg of the 3 color sliders xPos unless it is clicked, where it then controls the xPos of the color sliders and then can slide them dynamically.
here’s the code inside the gray slider:

this.onMouseUp=function(){
	stopDrag();
	}
this.onEnterFrame=function(){
	if (this.hitTest(_root._xmouse, _root._ymouse, true) and (this.hitTest(_root._xmouse, _root._ymouse, true)))    {
		this.startDrag(_parent.gscale._y, _parent.gscale._x, _parent.gscale._y, _parent.gscale._x+_parent.gscale._width);
			for(i=0;i<3;i++){
			//set xVal for all 3 sliders
			myName=eval("_parent.slider"+i);
			myName._x=this._x;
			}	
	}else //set slider x to avg of 3 sliders
	this._x=((_parent.slider0._x+_parent.slider1._x+_parent.slider2._x)/3);
}

–each piece works when i comment out the other part, but not together. i think my if/and or else statements aren’t quite right, but i’m stuck on how to fix it–ideas anybody?..
-mojo

could you include a sample fla? It’s just much faster than having to recreate the whole thing. Thank you.

ok, here it is–
i’ve got code that works on the grayscale slider, and the fmx code that doesn’t is inside, commented out–the code for the rgb sliders is inside each.

bonus question: the constrain on my 3 of 4 btnMCs startDrag is messed up–the green slider works fine, but the other 3 have some vertical play in them that i cant figure out…btw, the startDrag code is different than in the as dictionary–i couldn’t get theirs to work, so i just messed w. the arguments until it worked (kinda) (-:
gracias,
-mojo

I got your file… help me out here…

what is supposed to happen when I click on the gray slider?

when I click on blue, red, etc…?

if you’re sliding the r,g, or b slider the chosen one will slide along its range, while the gs slider will dynamically move to reflect the average of the 3 sliders xPositions

if the gs slider is clicked, it ‘takes over’, snaps the r,g,b sliders to the gs slider xPos and then should be able to dynamically move all 3 as you slide the gs slider up and down its scale

make sense?
:goatee:

think so… I’ll give it a shot…

Kind of a busy day, but I’ll give you the starting point. I think it will make sense to you. Before someone jumps… I did not consolidate the functions, even though that would be the best way to program it, simply because I dd not want to complicate it further. If you’re interested, we can discuss it after you get the effect you’re looking for.

This code illustrates the basics. You will notice two things…

  1. it is all in the actions layer of the main scene. Much easier to keep track of your code

  2. it doesnt look like yours. That is mainly a style thing, you should not feel bad about it at all. 10 people could get the same results with different code (more or less).

heres the code



fscommand("fullscreen", true); //you had that there
red=rgbslider.slider0 //these are just shortcuts or aliases
green=rgbslider.slider1 //same
blue=rgbslider.slider2 //same

startx=-100.9; // this establishes the left edge of my buttons
endx=96.0; // the right edge
myy=-19.2; // for now, this is the y value of the red square

red.onEnterFrame=function(){ //check for values on each frame
	
	
	if (this._y!=myy){ /* this all says, keep on x axis within limits of startx and endx */
		this._y=myy;
	}
	if(this._x<startx){
		this._x=startx;
	}else if(this._x>endx){
		this._x=endx;
	}
	
}
rgbslider.slider0.onPress=function(){ //you know these
	
	this.startdrag();
	}
rgbslider.slider0.onRelease=function(){
	
	this.stopdrag();
}

When I get a little more time, we’ll tackle the averages, but I can tell you that you practically have it. You’re almost there.

Good luck.

thanks for taking the time to look at it, inigo…
the deal is tho, that it has to be encapsulated inside the MC-(-i want to keep it OO as much as possible, and be able to drop it in any movie and use it)

the problem is in the MX code, where i’m hit and drag testing inside an onEnterFrame event–it works when i comment out one part or another, but not with both–maybe i’m splitting hairs and should just use the f5 style code thats on top of the gs button

take a look again, if you get a chance, but don’t sweat it–i’m just trying to get everything as tight as i can…
regards,
-mojo

well… the principal of the code is the same… you can just address to your needs. The grey slider piece I’ve yet to do… :slight_smile: