Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package otherlib.loaders {
- import flash.events.MouseEvent;
- import otherlib.loaders.ACOW;
- import otherlib.ringmas.loadervar;
- //some odd notes the lbl or labeler is to prevent multiple radio classes to all have buttons with the same name...
- //creating a crash. so it should be e.target.name == lbl + i in theory
- //closed buttons will be lbl + i + "c" for float over
- //dont wont the buttons to be spaced out so they will be named 0,1,2... etc instead of 0,2,4 using iNow
- public class radioClass {
- public var buttonArray:Array = [];
- public var sFunc:Function;
- public var lbl:String;
- public function buildRadio(total:int, xSide:int, ySide:int, ySpacer, wSide:int, starter:int, labeler:String, sFun:Function, sStage) {
- radioButtonAddNumber(total, xSide, ySide, ySpacer, wSide, buttonArray, sStage);
- buttonArray[(starter * 2) + 1].visible = true; //one has to be visible its a radio
- sFunc = sFun;
- lbl = labeler;
- var iNow:int = new int(0);
- for(var i = 0; i < buttonArray.length; i = i + 2) {
- buttonArray[i].addEventListener(MouseEvent.CLICK, radioChange);
- buttonArray[i].name = labeler + iNow;
- buttonArray[i+ 1].name = labeler + iNow + "c";
- iNow++;
- }
- }
- //a function that makes a bunch of radio buttons...
- public function radioButtonAddNumber(total:int, xSide:int, ySide:int, ySpacer, wSide:int, sArray, sStage) {
- for (var i:Number = 0; i < total; i++) {
- radioButtonAdd(xSide, ySide + (ySpacer * i), wSide, sArray, sStage);
- }
- }
- //add a radio button the array provided
- public function radioButtonAdd(xSide:int, ySide:int, wSide:int, sArray:Array, sStage) {
- var tempFile:String;
- if(loadervar.ldRemote == true){
- tempFile = loadervar.ldBaseXML;
- }
- else {
- tempFile = "../";
- }
- var ac:ACOW = new ACOW();
- ac.makeLoadChange(tempFile + "images/button/radioopen.png", xSide, ySide, wSide, wSide, sArray, sStage);
- var ac1:ACOW = new ACOW();
- ac1.makeLoadChange(tempFile + "images/button/radioclosed.png", xSide, ySide, wSide, wSide, sArray, sStage);
- buttonArray[buttonArray.length - 1].visible = false;
- }
- //show all the buttons in the open position, hide all closed buttons
- public function resetButtonOpen() {
- for(var i = 0; i < buttonArray.length; i = i + 2) {
- buttonArray[i].visible = true;
- buttonArray[i + 1].visible = false;
- }
- }
- //set the one button that needs to be changed
- public function setButtonClosed(but:int) {
- buttonArray[but].visible = false;
- buttonArray[but + 1].visible = true;
- }
- //radio buttons have been clicked Change NOW!
- public function radioChange(e:MouseEvent) {
- resetButtonOpen();
- var iNow:int = new int(0);
- for(var i = 0; i < buttonArray.length; i = i + 2) {
- if(e.target.name == lbl + iNow) {
- setButtonClosed(i);//array spot is easier here...
- sFunc(iNow); // toss to the main game the number that got selected
- }
- iNow++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement