actionscript 3 - Using the currentLabel property -
i doing project in as3. simple "slot machine." when handle clicked there 3 movieclips play starting @ random frames , when clicked again stop on random frame.
now, part i'm having trouble with: need evaluate 3 frames (using currentlabel) , if match launch function called playwin. if don't match nothing happen.
i tried standard "if" statement currentlabel property tripping me up. don't know how compare 3 statements. i've had practice comparing two.
any 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); var num3:number = math.round(1+ math.random() * 10); _spinner1.gotoandstop(num1); _spinner2.gotoandstop(num2); _spinner3.gotoandstop(num3); } } //private function playwin():void{ //_lights.play(); } }
in stopspinner method, need check if 3 spinners framelabel string match.
maybe make new method called checkspinners, returns true if match, , false if don't. use @ end of 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 need 2 check 2 combinations of labels each other, because of process of elimination, if both true, last combination must match too.
Comments
Post a Comment