I do still have one problem though, how do I limit how far it can move left and right, I have tried to find something about this, but cant… I dont want them to be able to move the image too far so it shows the blank background.
That doesnt really help. Everyone used to be so helpful, you could just explain what I had to do without actually telling me, instead of talking in code =\
Ember: You can use an if statement (fluid_one posted a method of the if statement, but a bit different).
Here is an example of how this would work…
[AS]var howFarRight = 550;
var howFarLeft = 0;
if (clip._x >= howFarRight){
clip._x = howFarRight;
} else if (clip_x <= howFarLeft){
clip._x = howFarLeft;
}[/AS]
(assumes your clips instance name is “clip”)
This says that if the clips x position is greater than or equal to the howFarRight variable, then it won’t be able to move any further because it will keep being placed at the howFarRight variable position.
The else if does the same thing, but checks the howFarLeft variable for moving left.
the howFarLeft and howFarRight variables are how far left and right you want to go on the stage.
So if your stage width is 550 and you want it to go all the way to the edge, then your howFarRight would be 550 (being 550 pixels to the right).
Now remember though, AS positions your clips according to its registration point, so if your clip has a centered registration point, then moving it all the way to the edge will take off that half of the clip.
What you could do is this though…
[AS]var howFarRight = 550-(clip._width/2);
var howFarLeft = clip._width/2;[/AS]
This obviously gets half of the width of the clip, and uses that to help decided how far this clip should go so that it doesn’t get cut off because of the registration clip position.
(note: above equations are for if your movie clip has a centered registration point)
What I want to do is, be able to move the image around the screen, without the right hand edge moving so far it reveals the background… and same with the left, so I think that will mean setting the howFarLeft/Right to the width of the image minus the width of the stage.
[AS] var y;
y = y+2;
ud = _root.v-y;
_root.mover._y = ud;[/AS]
Can be simplified with just a simple…
[AS]_root.mover._y -= 2;[/AS]
(changing -= to += where necessary)
That reduces 4 lines to 1 line
Problem 2) You don’t have to define howFarLeft and howFarRight in each onKeyPress. Just do it in an onClipEvent(load)
[AS]onClipEvent (load) {
var howFarRight = 682;
var howFarLeft = 0;
var howFarUp = 0;
var howFarDown = 146;
}[/AS]
Problem 3) You don’t need to do if statements for howFarLeft AND howFarRight on each keypress, if the clip is moving right, you only need to check the howFarRight, and if you are moving it left, you only need to check the howFarLeft.
Problem 4) Somtimes you wrote mover_x instead of mover<B>.</B>_x (that dot makes a difference)… also, you don’t need to do mover._x, you can use this._x as well since the clip the code is on is the clip you are moving.
Problem 5) Flash’s _y axis is different, up is negative, and down is positive, so your <= and >= if statements were mixed up there.
Ive attached the fixed file. I commented a few things, but since its basically the same code being reused in slightly different ways I didn’t comment the whole thing.