日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

AS3单选框实现

發(fā)布時(shí)間:2024/4/14 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 AS3单选框实现 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

public class RadioCell extends Sprite
?? ?{
?? ??? ?public var radioMc:Mc;
?? ??? ?public var id:Object;
?? ??? ?public var radioName:String;
?? ??? ?
?? ??? ?public function RadioCell(_id:Object = null, _name:String = "", content:String = "", size:int = 14, isBold:Boolean = false)
?? ??? ?{
?? ??? ??? ?this.buttonMode = true;
?? ??? ??? ?this.useHandCursor = true;
?? ??? ??? ?if(null != _id)
?? ??? ??? ?{
?? ??? ??? ??? ?setData(_id, _name, content, size, isBold);
?? ??? ??? ?}
?? ??? ?}
?? ??? ?
?? ??? ?public function setData(_id:Object, _name:String, content:String, size:int = 14, isBold:Boolean = false):void
?? ??? ?{
?? ??? ??? ?id = _id;
?? ??? ??? ?radioName = _name;
?? ??? ??? ?
?? ??? ??? ?radioMc = new fl_oneSelectMc();
?? ??? ??? ?this.addChild(radioMc);
?? ??? ??? ?radioMc.gotoAndStop(1);
?? ??? ??? ?
?? ??? ??? ?var htmlContent:String = "<font color='#FFCC99' size='"+size+"' face='SimSun'>"+content+"</font>";
?? ??? ??? ?if(true == isBold)
?? ??? ??? ?{
?? ??? ??? ??? ?htmlContent = "<b>"+htmlContent+"</b>";
?? ??? ??? ?}
?? ??? ??? ?
?? ??? ??? ?var txt:TextField = this.createTxtField(htmlContent);
?? ??? ??? ?this.addChild(txt);
?? ??? ??? ?txt.x = 21;
?? ??? ??? ?
?? ??? ??? ?if(txt.textHeight + 5 > 20)
?? ??? ??? ?{
?? ??? ??? ??? ?radioMc.y = (txt.textHeight - 15)*0.5 + 2;
?? ??? ??? ?}
?? ??? ??? ?else
?? ??? ??? ?{
?? ??? ??? ??? ?txt.y = (15 - txt.textHeight)*0.5 + 2;
?? ??? ??? ?}
?? ??? ??? ?
?? ??? ??? ?RadioManager.getInstance().addItem(this);
?? ??? ?}
?? ??? ?
?? ??? ?public function clearSelect():void
?? ??? ?{
?? ??? ??? ?radioMc.gotoAndStop(1);
?? ??? ?}
?? ??? ?
?? ??? ?public function Select():void
?? ??? ?{
?? ??? ??? ?radioMc.gotoAndStop(2);
?? ??? ?}
?? ??? ?
?? ??? ?private function createTxtField(str:String):TextField
?? ??? ?{
?? ??? ??? ?var txtField:TextField = new TextField();
?? ??? ??? ?txtField.selectable = false;
?? ??? ??? ?txtField.width =? 120; ?
?? ??? ??? ?txtField.height =? 50;
?? ??? ??? ?txtField.autoSize = TextFieldAutoSize.LEFT;
?? ??? ??? ?txtField.htmlText = str;
?? ??? ??? ?return txtField;
?? ??? ?}
?? ?}

//管理器

public class RadioManager

{
?? ??? ?private static var instance:RadioManager;
?? ??? ?
?? ??? ?private var radioTypesDict:Dictionary;
?? ??? ?private var radioValueDict:Dictionary;
?? ??? ?
?? ??? ?public function RadioManager()
?? ??? ?{
?? ??? ??? ?radioTypesDict = new Dictionary();
?? ??? ??? ?radioValueDict = new Dictionary();
?? ??? ?}
?? ??? ?
?? ??? ?public static function getInstance():RadioManager
?? ??? ?{
?? ??? ??? ?return instance = instance || new RadioManager();
?? ??? ?}
?? ??? ?
?? ??? ?/**
?? ??? ? * 添加單選項(xiàng)
?? ??? ? */?? ??? ?
?? ??? ?public function addItem(radioCell:RadioCell):void
?? ??? ?{
?? ??? ??? ?if(null == radioTypesDict[radioCell.radioName])
?? ??? ??? ?{
?? ??? ??? ??? ?radioTypesDict[radioCell.radioName] = [];
?? ??? ??? ?}
?? ??? ??? ?var arr:Array = radioTypesDict[radioCell.radioName];
?? ??? ??? ?radioCell.addEventListener(MouseEvent.CLICK, onMouseClickHandler);
?? ??? ??? ?arr[arr.length] = radioCell;
?? ??? ?}
?? ??? ?
?? ??? ?private function onMouseClickHandler(e:MouseEvent):void
?? ??? ?{
?? ??? ??? ?var radioCell:RadioCell = e.currentTarget as RadioCell;
?? ??? ??? ?//已選的就不再遍歷了
?? ??? ??? ?if(radioValueDict[radioCell.radioName] == radioCell)
?? ??? ??? ?{
?? ??? ??? ??? ?return;
?? ??? ??? ?}
?? ??? ??? ?
?? ??? ??? ?//上一次選中的去掉
?? ??? ??? ?if(null != radioValueDict[radioCell.radioName])
?? ??? ??? ?{
?? ??? ??? ??? ?(radioValueDict[radioCell.radioName] as RadioCell).clearSelect();
?? ??? ??? ?}
?? ??? ??? ?
?? ??? ??? ?//選中這次點(diǎn)擊
?? ??? ??? ?radioCell.Select();
?? ??? ??? ?radioValueDict[radioCell.radioName] = radioCell;
?? ??? ?}?? ??? ?
?? ??? ?
?? ??? ?/**
?? ??? ? * 獲得單選框的值
?? ??? ? * @param _name 類型名
?? ??? ? * @return
?? ??? ? */?? ??? ?
?? ??? ?public function getSelectedRadioId(_name:String):Object
?? ??? ?{
?? ??? ??? ?return (radioValueDict[_name] as RadioCell).id;
?? ??? ?}
?? ??? ?
?? ??? ?/**
?? ??? ? * 設(shè)置默認(rèn)選中
?? ??? ? * @param _name 類型
?? ??? ? * @param id 標(biāo)識(shí)
?? ??? ? */?? ??? ?
?? ??? ?public function setDefaultSelectedRadio(_name:String, id:Object):void
?? ??? ?{
?? ??? ??? ?//遍歷
?? ??? ??? ?for each(var cell:RadioCell in radioTypesDict[_name])
?? ??? ??? ?{
?? ??? ??? ??? ?if(cell.id == id)
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?cell.Select();
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ?}
?? ??? ?
?? ??? ?/**
?? ??? ? * 設(shè)置選框不可點(diǎn)
?? ??? ? */?? ??? ?
?? ??? ?public function disableRadioType(_name:String):void
?? ??? ?{
?? ??? ??? ?for each(var cell:RadioCell in radioTypesDict[_name])
?? ??? ??? ?{
?? ??? ??? ??? ?cell.buttonMode = false;
?? ??? ??? ??? ?cell.useHandCursor = false;
?? ??? ??? ??? ?cell.mouseEnabled = false;
?? ??? ??? ??? ?cell.removeEventListener(MouseEvent.CLICK, onMouseClickHandler);
?? ??? ??? ?}
?? ??? ?}
?? ??? ?
?? ??? ?/**
?? ??? ? * 設(shè)置選框可點(diǎn)
?? ??? ? */?? ??? ?
?? ??? ?public function ableRadioType(_name:String):void
?? ??? ?{
?? ??? ??? ?for each(var cell:RadioCell in radioTypesDict[_name])
?? ??? ??? ?{
?? ??? ??? ??? ?cell.buttonMode = true;
?? ??? ??? ??? ?cell.useHandCursor = true;
?? ??? ??? ??? ?cell.mouseEnabled = true;
?? ??? ??? ??? ?cell.addEventListener(MouseEvent.CLICK, onMouseClickHandler);
?? ??? ??? ?}
?? ??? ?}
?? ??? ?
?? ?}

轉(zhuǎn)載于:https://my.oschina.net/u/185335/blog/179800

總結(jié)

以上是生活随笔為你收集整理的AS3单选框实现的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。