First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Tiran Dagan | Website: http://www.TiranDagan.com

Putting it all together

Since we do not want the user to have to press any keys, simply use the mouse, we need some form of continuous behaviour which aids in the scrolling functions. The trick is nifty: Each "sensitive area" is an instance of the same MoveClip "VRmove" which contains within it an empty MovieClip. A script is attached to the onFrame event of the empty MovieClip. This event is  triggered every single frame, at a frequency which is dependant on the frame rate you establish for your film. Too slow of a frame rate results in choppy motion. To fast will kill the CPU.

onClipEvent (enterFrame) {
var accelerate=40;

speed_lcl=_parent._parent.speed;
targetSpeed_lcl=_parent._parent.targetSpeed;

if ( (Math.abs(speed_lcl) > 0.05) or targetSpeed_lcl<>0) {

	speed_lcl += (targetSpeed_lcl-speed_lcl)/accelerate;

	currentX=_parent._parent.mainMovie._x;
	newX=currentX + speed_lcl;
	if (speed_lcl<0 and newX<0) 
		newX=_parent._parent.startX;
	else if (speed_lcl>0 and newX>_parent._parent.startX)
		newX=0;
		
	_parent._parent.mainMovie._x=newX;
	_parent._parent.speed=speed_lcl;

	}
}

Fig. 7 - Code for the empty movie clip in "VRMove"

This code does the following:

  1. Evaluate whether we should waste time on moving the large image by examining the current scroll speed. If the speed is faster than 0.05 (we are still moving) or we are being asked to accelerate (targetSpeed_lcl<>0) then perform the remaining of the routine. The reason we dont check for speed_lcl=0 is that our various routines might not hit "0" because of the deceleration effect.
  2. Acceleration/deceleration: Calculate the destination "x" position for the large image, and increase/decrease the speed according to user's mouse position.

As I mentioned - this code is reused in the 7 instances of "VRmove" (the pink shaded squares above). The only difference between each instance is the target speed they establish. In order to save on coding time, I take advantage of the instance name to determine the functionality of each instance of "VRmove" as following:

on (rollOver) {
var slow=2;
var medium=5;
var fast=10;
instance=this._name;

if (instance=="Stop") {
	_parent.targetSpeed=0;
} else if (instance=="Left") {
	_parent.targetSpeed=slow;
} else if (instance=="LeftF") {
	_parent.targetSpeed=medium;
} else if (instance=="LeftFF") {
	_parent.targetSpeed=fast;
} else if (instance=="Right") {
	_parent.targetSpeed=-1 * slow;
} else if (instance=="RightF") {
	_parent.targetSpeed=-1 * medium;
} else if (instance=="RightFF") {
	_parent.targetSpeed=-1 * fast;
}
}

on (rollOut) {
_parent.targetSpeed=0
}

Note: The rollOut event saves us from the case in which a user abruptly moves their mouse out of the window and gets frozen in continuous scrolling

I added a "Guides" button to this movie which demonstrate the position of the "sensitive areas". If you have any other questions about this code drop me a line at tiran@TiranDagan.com and visit my website www.6footmedia.com. If you are interrested in further development of this concept, feel free to contact us.

» Level Intermediate

Added: 2001-10-12
Rating: 8.94 Votes: 134
(10 being the highest)
» Author
No details available.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.