Search Tutorials
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:
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.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|