PDA

View Full Version : help?


tinyk
04-02-2004, 05:16 PM
i got this off of another site and am trying to understand it. the part i don't understand is:

function moveimage (movex, movey) {

i understand that "moveimage" is the name of the function (right?), but what are movex and movey, and why are they in parenthesis?

Colin Campbell
04-02-2004, 06:02 PM
moveimage is a user-created function, and movex and movey are variables that can be defined when using the function. For example:

function moveimage (movex, movey) {
this._x = movex;
this._y = movey;
}

Which would then be used like so:

myMC.moveimage (100,100);

In this scenario, movex (a variable) would be 100, same with movey. Hope thats easy enough to understand :)

nousername
04-02-2004, 06:06 PM
move the x coordinate and move the y coordinate... variables set up elsewhere in the code i assume... they are in paranthesis since they are the parameters of the method.... they affect how the method is executed....

tinyk
04-02-2004, 06:13 PM
thanks!

since this comes so easily to you, could you help with the second part? movey is defined as the y coordinate for a MC (movex similarily). in trying to get the MC to scroll, the following was applied to a button:

on (press) {
var intervalID = setInterval (_root.moveimage, 10, 0, -1);
}
}

why are their four things within the setInterval? what are those? i know the last is the increment of which _y moves, but what about the others?

thanks for your help by the way!!

Colin Campbell
04-02-2004, 08:16 PM
Could you send me the link to the tutorial/code you're following? I'm having a hard time understanding how that code would work correctly, because something like that would be:

on (press) {
var intervalID = setInterval (_root.moveimage (100,100), 10);
}
}

the last 1 being the millseconds between it executing the function.

tinyk
04-03-2004, 09:50 AM
here's the file i downloaded. i'm using it to scroll a movie clip (not a map), and will only be scrolling down and up, not left and right.

Colin Campbell
04-03-2004, 01:39 PM
Ok, thanks.

What exactly are you trying to do? Because I just deleted the left and right buttons and it moves up and down perfectly. You could just copy and paste the code from the file into your own. All you'd need is the code on the actions frame, the top and bottom buttons, and then paste that code on your own up and down buttons.

Let me figure out how this function is working next :)

EDIT: alright:

var intervalID = setInterval (_root.moveimage, 10, 0, -0.5);

first number, 10, is the number of milliseconds between moveimage executing.
second number, 0, is the amount of X movement.
last number, -0.5, is the amount of vertical (y) movement

you would change the last number if you wanted it to scroll faster, and the first number if you wanted it to scroll smoother (it would take more processor power though)

tinyk
04-03-2004, 05:55 PM
i'm trying to get it to stop scrolling once _y reaches a certain point. i did an if statement, but i think it's wrong -- it only stops scrolling if i scroll, release, then press again (after the _y has reached it's limit). i think it's only checking the _y of the movie clip when you press down, and not continually checking, while the mouse is down. does that make sense?
any ideas?

thanks for your explanations! very helpful!!
how did you know what each was -- does setInteral always work that way....ie. - setInterval (target function?, milliseconds, _x, _y) ? does it depend?

Colin Campbell
04-03-2004, 07:19 PM
1. Nope, you only need setInterval (target function, # of milliseconds between execution). I'm not exactly familiar with setInterval, but I suppose after that you enter in the optional parameters for your function.

2. I'm figuring it out ATM. Gimme a couple minutes The script will be a little different though, as I'm removing the movex capabilites because its not needed, and replacing it with something a little more geared towards your needs :)

Colin Campbell
04-03-2004, 07:27 PM
See attachment, I could only get it to work when the picture is moving down, and not automatically stop when the picture is moved down too far. Sorry, but I've got to run shortly. Good luck :)

tinyk
04-04-2004, 10:10 AM
thanks for all your help! it works great for what i need! thanks!