A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: A little help needed: Spinner

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    9

    A little help needed: Spinner

    Greetings all...

    I have been working on this for sometime and have managed to cut and chop together something that works, with help from various places, including the help from lovely people here.

    Project:

    A Spinning, wheel of fortune style "spinner" that rotates and finally choses a winning amount.

    Problems:

    a) I cannot seem to work out how to reduce the "slow down" of the spinning. I would ideally want the thing to rotate about 5-8 seconds before it finally stops on a section

    b) I would ideally be able to use a button to start the whole thing off, it seems that I have to click and drag...

    Plee

    If anyone could help me with this I could be massively in your debt, I am pretty new at flash (this is my first real learning experience)

    Thank again if anyone can help.

    CopiousFox

    wheelspinner1.zip

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Can you post a CS4 version of your fla here? or post the code you are using?

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    9
    Indeed I can... I think here you go mate.

    wheelspinnercs4.zip

    Thanks again

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Does the code need to be AS1?

  5. #5
    Junior Member
    Join Date
    Sep 2010
    Posts
    9
    it can be anything really, i'm just mashing together different parts of things ive found... its basically for a display that'll be on a touch screen tv

  6. #6
    :
    Join Date
    Dec 2002
    Posts
    3,518
    AS3 code on timelime...

    Code:
    stop();
    
    var minSpinTime:Number=5*1000;
    var maxSpinTime:Number=8*1000;
    var speed:Number=4.5;
    var friction:Number=0.98;
    
    var amt:Number=speed;
    var lengthOfSpin:Number;
    var rate:int=1000/stage.frameRate;
    
    
    wheel.buttonMode=true;
    bgColorWheel.buttonMode=true;
    wheel.addEventListener(MouseEvent.CLICK, setUpSpin, false,0,true);
    bgColorWheel.addEventListener(MouseEvent.CLICK, setUpSpin, false,0,true);
    
    function setUpSpin(e:Event):void {
    	wheel.removeEventListener(MouseEvent.CLICK, setUpSpin, false);
    	bgColorWheel.removeEventListener(MouseEvent.CLICK, setUpSpin, false);
    	amt=speed;
    	lengthOfSpin=Math.round(Math.random()*(maxSpinTime-minSpinTime))+minSpinTime;
    	wheel.addEventListener(Event.ENTER_FRAME, doSpin, false,0,true);
    }
    
    function doSpin(e:Event):void {
    	lengthOfSpin-=rate;
    	wheel.rotation+=(amt*=friction);
    	if (lengthOfSpin<0) {
    		wheel.removeEventListener(Event.ENTER_FRAME, doSpin, false);
    		wheel.addEventListener(MouseEvent.CLICK, setUpSpin, false,0,true);
    		bgColorWheel.addEventListener(MouseEvent.CLICK, setUpSpin, false,0,true);
    	}
    }
    Last edited by dawsonk; 11-08-2010 at 12:06 PM.

  7. #7
    Junior Member
    Join Date
    Sep 2010
    Posts
    9
    dude thats fantastic!

    I had to change a few numbers but thanks alot for your help!

    Didn't think I was going to be able to finish this

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center