开发者

Using the currentLabel property

开发者 https://www.devze.com 2023-02-11 09:01 出处:网络
I am doing a project in AS3. It is a simple \"slot machine.\" When the handle is clicked there are three MovieClips that play starting at random frames and when clicked again they stop on a random fra

I am doing a project in AS3. It is a simple "slot machine." When the handle is clicked there are three MovieClips that play starting at random frames and when clicked again they stop on a random frame.

Now, the part I'm having trouble with: I need AS to evaluate the three frames (using currentLabel) and if they match launch a function called playWin. If they don't match then nothing will happen.

I tried a standard "if" statement but the currentLabel property is tripping me up. I also don't know how to compare three statements. I've only had practice comparing two.

Any help would be appreciated!

package com.chandelle {
import flash.display.MovieClip;
import flash.display.FrameLabel;

import flash.events.MouseEvent;

public class Main extends MovieClip {
    var _spinner1:Spinner = new Spinner();
    var _spinner2:Spinner = new Spinner();
    var _spinner3:Spinner = new Spinner();
    var _lights:Lights = new Lights();

    public function Main() {


        var machine:Machine = new Machine();
        this.addChild(machine);
        machine.x = stage.stageWidth/2;
        machine.y = stage.stageHeight/2;


        machine.addChild(_lights);
        _lights.x = 14;
        _lights.y = -212;
        _lights.stop();

        var handle:Handle = new Handle();
        machine.addChild(handle);
        handle.x = 257;
        handle.y = -70;
        handle.addEventListener(MouseEvent.CLICK, spinSpinner);


        machine.addChild(_spinner1);
        _spinner1.x = 140;
        _spinner1.stop();
        _spinner1.addEventListener(MouseEvent.CLICK, stopSpinner);


        machine.addChild(_spinner2);
        _spinner2.x = 8;
        _spinner2.stop();
        _spinner2.addEventListener(MouseEvent.CLICK, stopSpinner);


        machine.addChild(_spinner3);
        _spinner3.x = -123;
        _spinner3.stop();
        _spinner3.addEventListener(MouseEvent.CLICK, stopSpinner);
    }
    private function spinSpinner(evt:MouseEvent):void {
        var num1:Number = Math.round(1+ Math.random() * 10);
        var num2:Number = Math.round(1+ Math.random() * 10);
        var num3:Number = Math.round(1+ Math.random() * 10);
        _spinner1.gotoAndPlay(num1);
        _spinner2.gotoAndPlay(num2);
        _spinner3.gotoAndPlay(num3);
    }
    private function stopSpinner(evt:MouseEvent):void{
        var num1:Number = Math.round(1+ Math.random() * 10);
        var num2:Number = Math.round(1+ Math.random() * 10);
        v开发者_Go百科ar num3:Number = Math.round(1+ Math.random() * 10);
        _spinner1.gotoAndStop(num1);
        _spinner2.gotoAndStop(num2);
        _spinner3.gotoAndStop(num3);
    }



    }


    //private function playWin():void{
        //_lights.play();
    }

}  


In your stopSpinner method, you need to check if all three spinners framelabel string match.

Maybe make a new method called checkSpinners, that returns true if they all match, and false if they don't. Then use it at the end of your stopSpinner method.

private function stopSpinner(evt:MouseEvent):void
{
    var num1:Number = Math.round(Math.random() * 10) + 1;
    var num2:Number = Math.round(Math.random() * 10) + 1;
    var num3:Number = Math.round(Math.random() * 10) + 1;
    _spinner1.gotoAndStop(num1);
    _spinner2.gotoAndStop(num2);
    _spinner3.gotoAndStop(num3);

    if (checkSpinners()) 
    {
        playWin();
    }
}

private function checkSpinners():Boolean 
{
    var label1:String = _spinner1.currentLabel;
    var label2:String = _spinner2.currentLabel;
    var label3:String = _spinner3.currentLabel;

    return ((label1 == label2) && (label1 == label3));
}

You only need two check two combinations of the labels with each other, because of the process of elimination, if they both are true, then the last combination must match too.

0

精彩评论

暂无评论...
验证码 换一张
取 消