Skip to main content
Inspiring
April 4, 2012
Answered

flash spinner questoin

  • April 4, 2012
  • 2 replies
  • 594 views

hey guys,

I'm looking to top off a little board game. So I've been looking for a spinner like the old twister style. Now in my search I found something that is close but works based upon how long you hold down the wheel. is there a way to make this function with a flick up instead of a mouse hold?  here's the code I found,

import flash.display.*;

import flash.events.*;

import flash.utils.getTimer;

import fl.transitions.Tween;

import fl.transitions.TweenEvent;

import fl.transitions.easing.*;

var spinning:Boolean = false;

var spinTween:Tween;

var startTime:Number;

wheel.addEventListener(MouseEvent.MOUSE_DOWN, setStartTime);//longer you hold the harder you spin

wheel.addEventListener(MouseEvent.MOUSE_UP, spinWheel);

function setStartTime(e:MouseEvent) {

startTime = getTimer();

}

function spinWheel(e:MouseEvent) {

if (!spinning) {

spinning = true;

var spinTime = Math.min(12.2, Math.max(2.12, ((getTimer() - startTime) / 100)));

var endRot = Math.round((spinTime * 360) + (Math.random() * 360));

spinTween = new Tween(wheel, "rotation", Regular.easeOut, wheel.rotation, endRot, spinTime, true);

spinTween.addEventListener(TweenEvent.MOTION_FINISH, spinTween_finished);

}

}

function spinTween_finished(e:TweenEvent):void

{

spinning = false;

}

This topic has been closed for replies.
Correct answer Ned Murphy

I should add that you won't need the MOUSE_DOWN listener anymore since you only care about the MOUSE_UP, though you could replace the MOUSE_UP with a CLICK event instead. 

Here is an example of what you could change that line to...

var spinTime = Math.min(12.2, Math.max(2.12, ((Math.random()*3000) / 100)));

That "Math.random()*3000" essentially says to take some random number of seconds up to three seconds for the time that would have been your pressing down time.

2 replies

Ned Murphy
Ned MurphyCorrect answer
Legend
April 4, 2012

I should add that you won't need the MOUSE_DOWN listener anymore since you only care about the MOUSE_UP, though you could replace the MOUSE_UP with a CLICK event instead. 

Here is an example of what you could change that line to...

var spinTime = Math.min(12.2, Math.max(2.12, ((Math.random()*3000) / 100)));

That "Math.random()*3000" essentially says to take some random number of seconds up to three seconds for the time that would have been your pressing down time.

Ned Murphy
Legend
April 4, 2012

If yiou want to retain some of what you aready have, then all you need to do is change

var spinTime = Math.min(12.2, Math.max(2.12, ((getTimer() - startTime) / 100)));

To not use the "getTimer() - startTime" and just replace it with some random number of millisceonds that would equate to the time you would otherwise have been holding down the mouse.