Hi, How would I get an MC to scroll a specified distance horizontally so for example I could have an MC 900 px wide but with a 300 px viewing area and a next and previous button and every time you hit next it scrolls 300 px and then knows not to scroll anymore once the MC is at it’s end. Would there be a way to do this so I could have one script that would be able to deal with MCs of any width?
search for infinite menu
scotty:)
Yeah, i’ve seen that infinite menu example before and it’s not exactly what i’m looking for. I’m interested in something that would have a next and previous button, and when you click next it would move the MC horizontally a specified distance and when you click previous it would move it back. Then i’d like to figure out a way for this to accomodate different size MCs.
that is possible, but when you want your viewable area 300px and scroll them each time 300px, your movies must have width with a factor 300…, so 600, 900 etc or you will have blanks, so with the above you can’t use it for any movie
scotty
How could I use _width for sections_mc instead of if (targetX>-1800) { so I can used different width MCs and only one function instead of a different function for each width MC?
And also, how could I set it up so onEnterFrame doesn’t continue forever…
What do you see wrong with this script? It seems to work but not really, try it out and see for yerself.
[AS]
targetX = 527;
maxWidth = section_mc._width
section_mc.onEnterFrame = function() {
this._x -= (this._x-targetX)/3;
};
forward_btn.onRelease = function() {
if (targetX<maxWidth) {
targetX -= 370;
trace(“true forward”)
}
};
back_btn.onRelease = function() {
trace(this._x)
if (targetX<527) {
targetX = 370;
trace(“true back”)
}
};
[/AS]
wyclef,
this one is working, i used the 300 step.
[AS]targetX = 0;
vel = 7
maxWidth = section_mc._width;
trace(maxWidth);
//when i made the section_mc.width = 1200, trace gives me 1201,
//so forwardbtn made one step to many
section_mc.onEnterFrame = function() {
this._x += (targetX-this._x)/vel;
};
forward_btn.onRelease = function() {
if (targetX>-maxWidth) {
targetX -= 300;
//trace(targetX);
}
};
back_btn.onRelease = function() {
if (targetX<0) {
targetX += 300;
}
};[/AS]
hope this will help you
scotty:fe:
Yes, this seems to work however you can still click forward button to scroll past the end of the MC instead of it stopping. How can this be fixed and also eliminate onEnterFrame when not needed.:rd:
here’s your fixed .fla
about eliminating the onEnterFrame, i think in this setup it isn’t possible (at least for me) without stopping it complete.
and why should you?
scotty
Hey, this is working much better! :bu:
Can you explain the significance of
[AS]
maxWidth = section_mc._width-52;
[/AS]
Specifically -52? Does it make sure that forward button doesn’t continue to scroll the MC after it’s reached the end? And about onEnterFrame, if this script was a function on the root level, and then the scrolling information was an external swf calling this function, when the external swf is unloaded, would that end the onEnterFrame loop or would that continue because the main function is on the root level?
Thanks!
i took a quick look at the file, and just an offhand guess, he did that because your mask has a _x of 50…so basically he is offsetting the movieclip by 52 pixels to make up for that difference.
the 52 is because of the begin targetX (50) and i put 2 extra, cause of some strange reason the maxWidth differs 1 from the width i made the mc.
to be sure i took 2 and that worked:q:
your other question i have to think about, it’s getting late here;)
scotty
you’re quite right, jeremy:}
just wanted to add, if this still doesn’t quite make sense, put a little red circle at the very very end of the “section_mc”.
test it with the “52”, and you will see that the red circle is at the very right of the mask. if you take out the 52, you will notice that the red circle shoots all the way to the left, and the end of your movieclip slides right off the screen.
Check if this is what you’re looking for…
[AS]stageW = Stage.width;
stageH = Stage.height;
space = 5;
speed = 3;
holder_mc.loadMovie(“rocket.jpg”);
this.createEmptyMovieClip(“temp”, 100);
this.createEmptyMovieClip(“temp2”, 101);
temp.onEnterFrame = function() {
if (holder_mc._width>0) {
step = holder_mc._width/3;
mask_mc._x = stageW/2-step/2;
mask_mc._y = stageH/2-holder_mc._height/2;
mask_mc._width = step;
mask_mc._height = holder_mc._height;
holder_mc._x = mask_mc._x;
holder_mc._y = mask_mc._y;
start = mask_mc._x;
a = holder_mc._x-space;
b = holder_mc._y-space;
c = holder_mc._x+mask_mc._width+space;
d = holder_mc._y+holder_mc._height+space;
with (this) {
lineStyle(2, 0x333333, 100);
moveTo(a, b);
lineTo(c, b);
lineTo(c, d);
lineTo(a, d);
lineTo(a, b);
}
rew_btn._y = ff_btn._y=d+space;
rew_btn._x = a;
ff_btn._x = a+ff_btn._width+space;
delete this.onEnterFrame;
}
};
temp2.onEnterFrame = function() {
holder_mc._x += ((start-n*step)-holder_mc._x)/speed;
};
ff_btn.onPress = function() {
n>=2 ? n=2 : n++;
};
rew_btn.onPress = function() {
n<=0 ? n=0 : n–;
};[/AS]
Forgot the fla… :beam:
Wow! That’s a ver nice script. I don’t think it will work for this but it’s definately useful. Thanks for sharing.
Right now, here is the latest script i’ve got. It’s working now too. I’m wondering though, if there is a way for it to work where onEnterFrame is only running when needed, like after clicking a button, or after the MC stops scrolling. I’m not sure, someone told me it’s not possible.
[AS]
_global.portfolioSection = function ()
{
targetX = 527;
path = _root.sectionMC_03.folioClip
maxWidth = path.section_mc._width-529;
velocity = 4;
path.section_mc.onEnterFrame = function() {
trace("ENTER FRAME")
this._x += (targetX-this._x)/velocity;
};
// Forward Button
path.forward_btn.onRelease = function() {
if (targetX>-(maxWidth-370)) {
targetX -= 370;
}
};
// Back Button
path.back_btn.onRelease = function() {
if (targetX<527) {
targetX += 370;
}
}
};
[/AS]
Ahhh i thought you wanted to load external pictures, so i managed to get the scrolling thing to adjust to the picture’s dimensions.
Hi, I’m still trying to set this up so onEnterFrame is only used when needed but this script still is not working properly, anyone notice anything wrong?
[AS]
_global.portfolioSection = function ()
{
targetX = 527;
path = _root.sectionMC_03.folioClip
maxWidth = path.section_mc._width-529;
velocity = 4;
path.section_mc.onEnterFrame = function() {
trace("ENTER FRAME")
this._x += (targetX-this._x)/velocity;
if(this._x==targetX){
this.onEnterFrame=null;
trace("NULL1")
}
};
// Forward Button
path.forward_btn.onRelease = function() {
if (targetX>-(maxWidth-370)) {
targetX -= 370;
path.section_mc.onEnterFrame = function() {
trace("ENTER FRAME")
this._x += (targetX-this._x)/velocity;
if(this._x==targetX){
this.onEnterFrame=null;
trace("NULL2")
}
};
}
};
// Back Button
path.back_btn.onRelease = function() {
if (targetX<527) {
targetX += 370;
path.section_mc.onEnterFrame = function() {
trace("ENTER FRAME")
this._x += (targetX-this._x)/velocity;
if(this._x==targetX){
this.onEnterFrame=null;
trace("NULL3")
}
};
}
}
};
[/AS]
Why do you have your buttons events inside the global function? And why are you using the onEnterFrame handler inside the button events? Thats unnecessary.
It’s in global because this function will be on the root level of the main movie and i’ll be calling the function from an external swf. OnEnterFrame is inside the button events because i’m trying to find a way to have onenterframe only running when needed. :ch: