I am doing a wheel of fortune style movie, where the user spins the wheel by flicking it with their mouse, and when it lands it performs an action. I am working with a script that works great - I just have been trying to change it from using a button to trigger the spinning to using the mouse to drag/flick it. I am starting to lose my mind on this, as I’ve tried everything I can think of but still nothing. Any help is greatly appreciated!
Currently, the stage holds 3 movieclips :- wheel, pointer and spin_btn. I want to eliminate “spin_btn” and physically spin the wheel with the mouse.
// Import the Tween Class and the Transition Classes
import mx.transitions.Tween;
import mx.transitions.easing.*;
// Set up an Array to store the segment details ie segment value, colours etc
// ( here I've only used 5 colours and values so each one is in triplicate on the wheel,
// if you wanted each segment to be different just enter 15 different values into the array )
var segDetails:Array = [ { name : "Red", value : 25, color : 0xFF0000 }, { name : "Yellow", value : 30, color : 0xFFFF00 },
{ name : "Green", value : 35, color : 0x00FF00 }, { name : "Blue", value : 40, color : 0x0000FF },
{ name : "Pink", value : 50, color : 0xFF00FF } ];
// A one off variable to count the items in the Array as the amount of items in the Array is less the amount of segments so the loop i can't be used
var segment = 0;
// Pass the Array items to the 15 segments on the stage
for ( var i:Number = 0; i < 15; i++ ){
// Reference the segment on the stage
var seg = wheel[ "seg" + i ];
// Pass the details to the segment
seg.name = segDetails[ segment ].name;
seg.value = segDetails[ segment ].value;
// Change the colour of the segment
segColor = new Color( seg.segmentFill );
segColor.setRGB( segDetails[ segment ].color );
// Increase the value of segment by 1 to read the next element in the Array and reset it to 0 if it reaches the Array end
segment++;
if ( segment == segDetails.length ) segment = 0;
}
// Spin the wheel
function spinWheel():Void
{
// Use a random number then multiply it by 24 so the degrees lands equally in the centre of the segment
var degrees:Number = Math.floor( ( Math.random() * 30 ) + 15 ) * 24;
// Create a length of time for the wheel to spin based on how many degrees its to turn
// altering the value here will increase/decresae the speed of the wheel
var time:Number = degrees / 200;
// Create a new tween
var wheelSpin:Tween = new Tween( wheel, "_rotation", Regular.easeOut, 0, degrees, time, true );
// When the motion has finished the onMotionFinished function is called
wheelSpin.onMotionFinished = function()
{
// Cycle through the segments to see which one is under the pointer
for ( var i:Number = 0; i < 15; i++ ){
if ( wheel[ "seg" + i ].hitTest( pointer._x, pointer._y, true ) ){
// Trace the winning segment
trace( "Segment colour : " + wheel[ "seg" + i ].name + ", Segment value : " + wheel[ "seg" + i ].value );
}
}
}
}
// Spin the wheel when the button is pressed
spin_btn.onPress = spinWheel;