Skip to main content
Participant
August 21, 2021
Answered

Control Spin Wheel Manually

  • August 21, 2021
  • 1 reply
  • 317 views

Hi, I'm having trouble with Actionscript 3.0. I searched a lot of spin wheel tutorial but mostly spin using motion tween or auto spin and get random results.

 

I would like to know the code for control the wheel manually. Like when we click the wheel n can move it follow your hand movement.

 

I attach some example of template from a website. 

 

 

This topic has been closed for replies.
Correct answer kglad

import flash.events.MouseEvent;
import flash.events.Event;

var startRotation:Number;

 

wheel.addEventListener(MouseEvent.MOUSE_DOWN, startSpinF);
wheel.addEventListener(MouseEvent.MOUSE_UP, stopSpinF);

 

function startSpinF(e: MouseEvent): void {
startRotation = Math.atan2(e.stageY - wheel.y, e.stageX - wheel.x)-Math.PI*wheel.rotation/180;
this.addEventListener(Event.ENTER_FRAME, spinF);
}
function stopSpinF(e: MouseEvent): void {
this.removeEventListener(Event.ENTER_FRAME, spinF);
}
function spinF(e:Event):void{
wheel.rotation = 180*(Math.atan2(mouseY - wheel.y, mouseX - wheel.x)-startRotation)/Math.PI;

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
August 21, 2021

import flash.events.MouseEvent;
import flash.events.Event;

var startRotation:Number;

 

wheel.addEventListener(MouseEvent.MOUSE_DOWN, startSpinF);
wheel.addEventListener(MouseEvent.MOUSE_UP, stopSpinF);

 

function startSpinF(e: MouseEvent): void {
startRotation = Math.atan2(e.stageY - wheel.y, e.stageX - wheel.x)-Math.PI*wheel.rotation/180;
this.addEventListener(Event.ENTER_FRAME, spinF);
}
function stopSpinF(e: MouseEvent): void {
this.removeEventListener(Event.ENTER_FRAME, spinF);
}
function spinF(e:Event):void{
wheel.rotation = 180*(Math.atan2(mouseY - wheel.y, mouseX - wheel.x)-startRotation)/Math.PI;

}

Participant
August 24, 2021

Thank You so much for the help. It works!

kglad
Community Expert
Community Expert
August 24, 2021

you're welcome