PDA

View Full Version : Click button and slide????


diggz
10-27-2005, 08:39 AM
Hi All,

Hope someone can help me out with question that I have.

Basically I have a movie that has a parallax scrolling background that moves in response to the left and right keys being pressed.

It works fine and great but I want to add another element to it, and this is my question - I need some code to paste onto buttons to make the different background movieclips slide to certain positions. ie: the positions that can also be reached using arrow keys.

There are three or four background movie clips that move at different speeds and the code shown below is pasted onto the the hero clip in the centre of the stage:

onClipEvent (load) {
gotoAndStop(1);
this.sonic.gotoAndStop(1);
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
gotoAndStop(1);
this.sonic.play();
_root.land._x -= 1;
_root.mid._x -= 15;
_root.mid2._x -= 11;
_root.mid3._x -= 15;
_root.trees2._x += 1;
_root.trees._x -= 1;
} else if (Key.isDown(Key.LEFT)) {
gotoAndStop(2);
this.sonic.play();
_root.land._x += 1;
_root.mid._x += 15;
_root.mid2._x += 11;
_root.mid3._x += 15;
_root.trees2._x -= 1;
_root.trees._x += 1;
} else {
this.sonic.gotoAndStop(1);
}

Does anyone know and tell me what code I could put on a button that would make these background mc's move to any set x position please?

Really hope someone can share the knowledge with me please :))

Thanks in anticipation

third EYE
10-27-2005, 09:07 AM
to start, if these are fairly generic actions, use a MovieClip.prototype

then attach each instantiated prototype to a listener that replies on key events

write a function within the prototype to check wether it's an acceptable actions (in bounds etc) when the listener is triggered

also, disregard anything I say if CyanBlue comes in ;)

diggz
10-27-2005, 09:15 AM
Hey ThirdEye,

Thanks for the reply - I kind of understand what you are saying, but clueless as to how to implement it!!! :(

Is there not some straightforward code that I could drop onto a button?
On click tell mc to go to x pos = 100 or something like that?
(I just invented an new AS format :)!!!!!)

third EYE
10-27-2005, 09:23 AM
mx.transition.Tween is probably what you are looking for

diggz
10-27-2005, 09:30 AM
Where can I find more pointers on this?

In theory it should be easy enough to do (famous last words!!!)

third EYE
10-27-2005, 09:35 AM
do a search on here for it... it's undocumented in MX2004 but there's tons of info on it :)

/edit: common implementation looks like this:

import mx.transitions.*;

MovieClip.prototype.easing = function(begin, end, speed, propMod) {
var tween_handler:Object = new Tween(this, propMod, Strong.easeIn, begin, end, speed, true);
};

where propMod is a string for the _x, _y, _alpha, _scale etc. of the MC

diggz
10-27-2005, 10:02 AM
I'm finding 'loads' of stuff on it - thanks for the suggestion.

"...I may be some time"

Thanks ThirdEye

;)

diggz
10-27-2005, 10:58 AM
...not getting very far, very fast! :(

There are a number of tweens etc... but none that is what I am looking.
Very interesting reading though.

I have attached my fla with some dummy buttons on there - does anyone have the time (or inclination) to have a look at it and see if they can get it to work - or tell me how to please?

I know it will be simple for someone out there - just can't get my head around it!!!

:confused: